trailsjs / sails-swagger

Swagger integration for sails.js
107 stars 47 forks source link

/swagger/doc not using global CORS settings #17

Open fed135 opened 8 years ago

fed135 commented 8 years ago

My current settings for CORS are:

allRoutes: true
origin: '*'
methods: 'GET, POST, PUT, DELETE, OPTIONS'

When accessing the /swagger/doc route (with the default config) I don't get my CORS headers. Just these:

Connection:keep-alive
Date:Thu, 17 Dec 2015 22:56:49 GMT
ETag:W/"f1f7-1299879629"
X-Powered-By:Sails <sailsjs.org>

But my other routes have the CORS headers:

Access-Control-Allow-Credentials:true
Access-Control-Allow-Origin:http://someothersite.com
Access-Control-Expose-Headers:
Connection:keep-alive
Content-Length:10887
Content-Type:text/html; charset=utf-8
Date:Thu, 17 Dec 2015 22:46:49 GMT
ETag:W/"2a87-3377312003"
X-Powered-By:Sails <sailsjs.org>
tjwebb commented 8 years ago

This might be a bug in sails, where manually-configured routes aren't picking up on the global CORS setting. Can you try manually defining a route for the swagger doc handler in config/routes.js, set the CORS config there, and see if that works?

Also, please see: https://github.com/tjwebb/sails-swagger/issues/16

fed135 commented 8 years ago

Not (fully) doing it. I tried with cors:true and also by explicitly defining my cors settings, still my allow-origin field is empty. It almost seems like the cors config is plainly overwritten at some point.

Access-Control-Allow-Credentials:true
Access-Control-Allow-Origin:
Access-Control-Expose-Headers:

I could try taking a look inside Sails to fix the issue. Will you guys still be looking at pull requests once you jump on Trails?

fed135 commented 8 years ago

Found the issue in sails-swagger

Specifying a cors config for the /swagger/doc route overwrites the global config. I simply removed the cors property from the config object.

18

Vanuan commented 8 years ago

Is this fixed? I'm still having this issue. Should I be using master version?

samuelagm commented 8 years ago

The npm version doesn't have this fix, but I can confirm its available in the latest commit. Updating the npm version would be wonderful. Thanks

itsheng commented 8 years ago

@tjwebb Would you mind updating the npm package? Thank you!

joseasrocha commented 8 years ago

I've published an updated npm package.

npm install sails-magik-swagger

washimimizuku commented 7 years ago

Is this abandoned? I still have the same problems described here with CORS

swaroopjayanthi9 commented 7 years ago

I am facing this issue, I am setting CORS value to true in cors.js, please suggest workaround at the earliest.

The above mentioned sails-magik-swagger isnt working