标签:methods max-age express set lang header post end ade
在app.js中配置跨域请求//设置允许跨域访问该服务.
app.use((req, res, next) => {
res.set({
‘Access-Control-Allow-Credentials‘: true,
‘Access-Control-Max-Age‘: 1728000,
‘Access-Control-Allow-Origin‘: req.headers.origin || ‘*‘,
‘Access-Control-Allow-Headers‘: ‘X-Requested-With,Content-Type‘,
‘Access-Control-Allow-Methods‘: ‘PUT,POST,GET,DELETE,OPTIONS‘,
‘Content-Type‘: ‘application/json; charset=utf-8‘
})
req.method === ‘OPTIONS‘ ? res.status(204).end() : next()
})
标签:methods max-age express set lang header post end ade
原文地址:https://blog.51cto.com/14284354/2508608