-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
请问一下CORS方案解决跨域问题该怎么处理呢? #3
Comments
app.get('/', (req, res) => {
res.set('Access-Control-Allow-Origin', 'http://example.com'); // 允许的origin
res.set('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,PATCH'); // 允许的HTTP方法
res.set('Access-Control-Allow-Headers', 'Content-Type'); // 支持的头信息字段,可以设置多种
res.set('Access-Control-Allow-Credentials', true); // 可选,表示是否允许发送Cookie
res.send('hello')
}) 也可以写成一个中间件,放在你要跨域的路由之前即可. 当然使用了nginx的话,可以配置nginx,原理还是一样,也是设置这些头信息.你可以去查查相关资料哈! |
非常感谢, 我试试看 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No description provided.
The text was updated successfully, but these errors were encountered: