axios withCredentials: true 跨域问题
const service = axios.create({baseURL: process.env.VUE_APP_BASE_API, // 环境变量base接口地址 url = base url + request urlwithCredentials: true, // 跨域请求时发送Cookietimeout: 60000, // 请求超时headers: {"Content-Type":
·
const service = axios.create({
baseURL: process.env.VUE_APP_BASE_API, // 环境变量base接口地址 url = base url + request url
withCredentials: true, // 跨域请求时发送Cookie
timeout: 60000, // 请求超时
headers: {
"Content-Type": "application/json; charset=UTF-8;"
}
});
node cors配置:
//解决跨域问题
var whitelist = ['http://example1.com', 'http://localhost:1888']
var corsOptions = {
origin: function (origin, callback) {
if (whitelist.indexOf(origin) !== -1) {
callback(null, true)
} else {
callback(new Error('Not allowed by CORS'))
}
},
maxAge: 5, //指定本次预检请求的有效期,单位为秒。
credentials: true, //是否允许发送Cookie
allowMethods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], //设置所允许的HTTP请求方法
allowHeaders: ['Content-Type', 'Authorization', 'Accept'], //设置服务器支持的所有头信息字段
exposeHeaders: ['WWW-Authenticate', 'Server-Authorization'] //设置获取其他自定义字段
}
app.use(cors(corsOptions))
更多推荐
已为社区贡献5条内容
所有评论(0)