当前位置: 首页 > news >正文

sails 跨域请求处理 -- config.cors

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

配置文件/config/cors.js 编辑

/**
 * Cross-Origin Resource Sharing (CORS) Settings
 * (sails.config.cors)
 *
 * CORS is like a more modern version of JSONP-- it allows your server/API
 * to successfully respond to requests from client-side JavaScript code
 * running on some other domain (e.g. google.com)
 * Unlike JSONP, it works with POST, PUT, and DELETE requests
 *
 * For more information on CORS, check out:
 * http://en.wikipedia.org/wiki/Cross-origin_resource_sharing
 *
 * Note that any of these settings (besides 'allRoutes') can be changed on a per-route basis
 * by adding a "cors" object to the route configuration:
 *
 * '/get foo': {
 *   controller: 'foo',
 *   action: 'bar',
 *   cors: {
 *     origin: 'http://foobar.com,https://owlhoot.com'
 *   }
 *  }
 *
 *  For more information on this configuration file, see:
 *  http://sailsjs.org/#!/documentation/reference/sails.config/sails.config.cors.html
 *
 */

module.exports.cors = {

  /***************************************************************************
  *                                                                          *
  * Allow CORS on all routes by default? If not, you must enable CORS on a   *
  * per-route basis by either adding a "cors" configuration object to the    *
  * route config, or setting "cors:true" in the route config to use the      *
  * default settings below.                                                  *
  *                                                                          *
  ***************************************************************************/

   allRoutes: true,

  /***************************************************************************
  *                                                                          *
  * Which domains which are allowed CORS access? This can be a               *
  * comma-delimited list of hosts (beginning with http:// or https://) or    *
  * "*" to allow all domains CORS access.                                    *
  *                                                                          *
  ***************************************************************************/

   origin: '*',

  /***************************************************************************
  *                                                                          *
  * Allow cookies to be shared for CORS requests?                            *
  *                                                                          *
  ***************************************************************************/

   credentials: true,

  /***************************************************************************
  *                                                                          *
  * Which methods should be allowed for CORS requests? This is only used in  *
  * response to preflight requests (see article linked above for more info)  *
  *                                                                          *
  ***************************************************************************/

   methods: 'GET, POST, PUT, DELETE, OPTIONS, HEAD',

  /***************************************************************************
  *                                                                          *
  * Which headers should be allowed for CORS requests? This is only used in  *
  * response to preflight requests.                                          *
  *                                                                          *
  ***************************************************************************/

   headers: 'content-type'

};

支持跨域请求

转载于:https://my.oschina.net/codingBingo/blog/818424

相关文章:

  • memcache命令
  • openlayers 3监听地图分辨率变化事件
  • Jython开发环境搭建
  • 【树莓派】树莓派网络对时间,时间调整
  • CodeDom系列四--Code生成
  • X 1 BT5kali
  • TCP协议中的三次握手和四次挥手(图解)【转】
  • 转载:年轻人,你着什么急?
  • 例25:二分查找
  • 常识性概念
  • 如何做出健壮的系统设计
  • Docker Registry服务器部署配置
  • C++类、继承、多态、虚函数
  • ZOJ 3329 One Person Game
  • pyinstall tkinter image
  • CSS 专业技巧
  • Docker下部署自己的LNMP工作环境
  • Git学习与使用心得(1)—— 初始化
  • HTTP 简介
  • JavaScript 是如何工作的:WebRTC 和对等网络的机制!
  • Java的Interrupt与线程中断
  • JS字符串转数字方法总结
  • 创建一种深思熟虑的文化
  • 构建工具 - 收藏集 - 掘金
  • 关于Java中分层中遇到的一些问题
  • 区块链将重新定义世界
  • 小程序开发之路(一)
  • 转载:[译] 内容加速黑科技趣谈
  • 京东物流联手山西图灵打造智能供应链,让阅读更有趣 ...
  • ​MPV,汽车产品里一个特殊品类的进化过程
  • ​无人机石油管道巡检方案新亮点:灵活准确又高效
  • #13 yum、编译安装与sed命令的使用
  • #我与Java虚拟机的故事#连载16:打开Java世界大门的钥匙
  • $ git push -u origin master 推送到远程库出错
  • $.ajax()方法详解
  • (01)ORB-SLAM2源码无死角解析-(66) BA优化(g2o)→闭环线程:Optimizer::GlobalBundleAdjustemnt→全局优化
  • (3)选择元素——(17)练习(Exercises)
  • (论文阅读32/100)Flowing convnets for human pose estimation in videos
  • (三)docker:Dockerfile构建容器运行jar包
  • (十五)Flask覆写wsgi_app函数实现自定义中间件
  • (转载)Google Chrome调试JS
  • .[hudsonL@cock.li].mkp勒索加密数据库完美恢复---惜分飞
  • .NET Standard / dotnet-core / net472 —— .NET 究竟应该如何大小写?
  • .NET 使用 ILMerge 合并多个程序集,避免引入额外的依赖
  • .Net(C#)常用转换byte转uint32、byte转float等
  • .net访问oracle数据库性能问题
  • .net下的富文本编辑器FCKeditor的配置方法
  • .Net组件程序设计之线程、并发管理(一)
  • .project文件
  • /var/lib/dpkg/lock 锁定问题
  • @NoArgsConstructor和@AllArgsConstructor,@Builder
  • [ element-ui:table ] 设置table中某些行数据禁止被选中,通过selectable 定义方法解决
  • [ 蓝桥杯Web真题 ]-布局切换
  • [boost]使用boost::function和boost::bind产生的down机一例
  • [BT]BUUCTF刷题第8天(3.26)