node-tutorial icon indicating copy to clipboard operation
node-tutorial copied to clipboard

express配置session

Open Wscats opened this issue 8 years ago • 0 comments

参考文档

token

跨域传cookies

很多浏览器默认是不传递cookies的,可以在前后端分别配置如下进行跨域传递

$.ajax({
	type: "get",
	url: "//localhost:3000/fe/getFemaleList",
	crossDomain: true,
	xhrFields: {
		withCredentials: true//允许cookie传递
	},
	async: true,
	data: {
		mobile: self.mobile,
		vcode: self.vcode
	},
	success(data) {
		console.log(data)
	}
});
app.use(function(req, res, next) {
	//res.append("Access-Control-Allow-Origin", "*");
	res.append("Access-Control-Allow-Origin", "http://localhost:12345");
	res.append("Access-Control-Allow-Credentials", true);// Allow Cookie
	//res.append("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
});

Wscats avatar Jan 27 '18 19:01 Wscats