查看“︁Node.js/cors”︁的源代码
来自康健生活
←
Node.js/cors
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
== 引言 == == 后端 == <blockquote><pre> npm install cors --save</pre></blockquote> <syntaxhighlight lang="javascript"> var cors = require('cors'); app.use(cors({ origin:['http://localhost:8080'], methods:['GET','POST'], alloweHeaders:['Conten-Type', 'Authorization'] }));</syntaxhighlight> == error == * header in the response is '' which must be 'true' when the request's credentials mode is 'include'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute : <syntaxhighlight lang="javascript" highlight="4"> server.use( cors({ origin: ['http://localhost:8080', '*', 'http://localhost:3000'], //设置原始地址 credentials: false, //允许携带cookie methods: ['GET','POST'], //跨域允许的请求方式 // allowedHeaders: 'Content-Type,Authorization,xc-auth,xc-gui', //允许请求头的携带信息 exposedHeaders: 'xc-db-response' }) );</syntaxhighlight>
返回
Node.js/cors
。
导航菜单
康健生活
搜索
user-page
通知
user-interface-preferences
个人工具
登录
五一
多读书,多运动,多到远处走走,再看看不一样的世界。