我有一个ExpressJS API服务器和一个在本地开发中运行的带有AngularJS应用程序的ExpressJS.
CORS GET请求工作正常,但POST和DELETE不发送任何cookie(凭据).
我尝试了各种配置选项,但从未让应用程序发送POST或DELETE的凭据.
我希望有人熟悉这一点,可能会看到我出错的地方.
我在/ etc/hosts中设置了两个本地域:
127.0.0.1 rsm.local
127.0.0.1 api.rsm.local
Run Code Online (Sandbox Code Playgroud)
所以http://rsm.local发送api请求http://api.rsm.local
AngularJS正在使用Restangular.
会话存储在MongoDB中,.rsm.local用于域,因此两个服务器都可以读取cookie.
客户端应用程序和api服务器都使用相同的cookie密钥和密钥.
app.use(express.session({
key: config.cookie_key,
secret: config.cookie_secret,
cookie: {
domain:'.rsm.local',
expires: config.cookie_expire
},
store: new mongoStore({
url: config.database,
collection: 'sessions',
auto_reconnect: true
})
}));
Run Code Online (Sandbox Code Playgroud)
这似乎可以很好地在两个应用程序之间共享会话状态.
API服务器是使用标准设置的,我认为是正确的CORS标头:
app.all('/api/*', function(req, res, next) {
res.setHeader('Access-Control-Allow-Origin', 'http://rsm.local:3000');
res.setHeader('Access-Control-Allow-Methods', 'GET,POST,PUT,DELETE,OPTIONS');
res.setHeader("Access-Control-Allow-Headers", "Accept, Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With");
res.setHeader('Access-Control-Allow-Credentials', true);
next();
});
Run Code Online (Sandbox Code Playgroud)
客户端应用程序AngularJS已将Restanguarl配置为正确发送凭据我相信:
angular.module('rsm').config(function (RestangularProvider) {
RestangularProvider.setBaseUrl('http://api.rsm.local:3001/api/v1');
RestangularProvider.setDefaultHttpFields({
withCredentials: true,
useXDomain : true
});
});
Run Code Online (Sandbox Code Playgroud)
所以GET请求一切正常(例如列出所有并列出一个): …
我想在csv行中读取,更新一个字段然后再用引号输出该行.
Row Example Input => "Joe", "Blow", "joe@blow.com"
Desired Row Example Output => "Joe", "Blow", "xxxx@xxxx.xxx"
My script below outputs => Joe, Blow, xxxx@xxxx.xxx
Run Code Online (Sandbox Code Playgroud)
它丢失了我想保留的双引号.
我尝试过各种各样的选择但到目前为止没有任何快乐......任何提示?
非常感谢!
require 'csv'
CSV.foreach('transactions.csv',
:quote_char=>'"',
:col_sep =>",",
:headers => true,
:header_converters => :symbol ) do |row|
row[:customer_email] = 'xxxx@xxxx.xxx'
puts row
end
Run Code Online (Sandbox Code Playgroud)