CORS
CORS in Express
跨域问题
安装
cors
1
2
3
4npm install cors --save-dev
const cors = require('cors');
app.use(cors());Handle
1
2
3
4
5
6
7app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*')
res.header('Access-Control-Allow-Headers', 'Authorization,X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method' )
res.header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PATCH, PUT, DELETE')
res.header('Allow', 'GET, POST, PATCH, OPTIONS, PUT, DELETE')
next()
})
本文作者: 孟 虎
本文链接: https://menghu1994.github.io/blog/2023/10/Nodejs/Express/cors/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!