lanceli / cnodejs-ionic

The mobile app of https://cnodejs.org made by Ionic 1.x, web demo http://lanceli.com/cnodejs-ionic
MIT License
1.52k stars 375 forks source link

请问你的项目是如何解决跨域问题的 #28

Closed 317365887 closed 8 years ago

317365887 commented 8 years ago

我看了你的JS源码,在读取数据和写入数据都是请求https://cnodejs.org/api/v1接口的,我在本机是localhost 应该算是跨域请求了,不过我没见你在JS里面做了什么特别处理,你是怎么处理跨域的?

lanceli commented 8 years ago

https://github.com/lanceli/cnodejs-ionic/issues/1

或直接见readme的cross origin部分 https://github.com/lanceli/cnodejs-ionic/blob/master/README.md

alsotang commented 8 years ago

话说,cnode 的 api 接口通通加了:add_header Access-Control-Allow-Origin *; 的啊

2015-09-15 15:40 GMT+08:00 Lance Li notifications@github.com:

1 https://github.com/lanceli/cnodejs-ionic/issues/1

或直接见readme的cross origin部分 https://github.com/lanceli/cnodejs-ionic/blob/master/README.md

— Reply to this email directly or view it on GitHub https://github.com/lanceli/cnodejs-ionic/issues/28#issuecomment-140308007 .

lanceli commented 8 years ago

@alsotang 嗯 他是调用本地cnode开发环境 所以~

alsotang commented 8 years ago

本地的话。。。只要启动的是 nodeclub,按理说也是没有跨域问题的。因为这个 cors 的语句我是在 nodejs 里面加的,不是在 nginx 上。

2015-09-15 15:51 GMT+08:00 Lance Li notifications@github.com:

@alsotang https://github.com/alsotang 嗯 他是调用本地cnode开发环境 所以~

— Reply to this email directly or view it on GitHub https://github.com/lanceli/cnodejs-ionic/issues/28#issuecomment-140311607 .

317365887 commented 8 years ago

恩,你的项目没问题,我只是想了解下怎么解决跨域问题,多谢大虾的支教

lanceli commented 8 years ago

@alsotang 酱紫啊 @317365887 https://github.com/cnodejs/nodeclub/blob/3ff1a90dd7121c42fc51254874df5af1ad9e5286/app.js cors包

alsotang commented 8 years ago

@lance

留个记录在这: https://github.com/cnodejs/nodeclub/blob/3ff1a90dd7121c42fc51254874df5af1ad9e5286/app.js#L154

2015-09-15 15:59 GMT+08:00 Lance Li notifications@github.com:

Closed #28 https://github.com/lanceli/cnodejs-ionic/issues/28.

— Reply to this email directly or view it on GitHub https://github.com/lanceli/cnodejs-ionic/issues/28#event-409513433.

317365887 commented 8 years ago

恩,我在网上也找了个跨域的方案,然后我 是用$http来操作数据的,网上要在JS这边加个$httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8'; 这个配置,后端我用PHP 我设置了header('Access-Control-Allow-Origin: *');才能跨域提交,我看作者的项目是用$resource来获取的,看JS里面没有什么特别设置,所以就想问问后端有什么特别设置