Closed vitorbaptista closed 8 years ago
Hey @vitorbaptista ,
So the cors support included in swagger-node-runner is nothing more than including the "cors" module (https://www.npmjs.com/package/cors) in the pipe that you define in your swagger config.
So, for example, you can see here: https://github.com/theganyo/swagger-node-runner/blob/master/test/assets/project/config/default.yaml that on line 29, it includes "cors" as part of the pipe. Thus, all routes handled as a swagger controller will include cors support. If you don't want cors, just remove that fitting from your pipe.
Does that help?
Also, I should have mentioned, if you want it on the swagger-raw pipe, you should be able to just add it there as well.
Thanks for the hint, @theganyo. That really helped! I was able to sort of enable CORS on the swagger_raw
pipe, but it feels as if I'm doing it the wrong way.
My swagger configuration file looks like:
swagger:
bagpipes:
swagger_raw:
name: swagger_raw
swagger_raw_cors:
- cors
- swagger_raw
# ...
I tried adding cors
to the actual swagger_raw
, but couldn't figure out how. The only way I found was creating a new bagpipe which pipes cors
and then the original swagger_raw
. Is there an easier way of doing this?
If I'm not mistaken, I believe you could just drop the first definition (swagger_raw).
Thanks a lot for your help, @theganyo. This change worked: https://github.com/opentrials/api/pull/24/commits/0cc27e931e809db00022da6ac04d91f6dec26462
Awesome!
I'm running a server like:
Some routes have CORS enabled, but not others (like
/v1/swagger.yaml
, maybe because it's usingx-swagger-pipe: swagger-raw
). Adding theroutes: { cors: true }
to theserver.connection()
call seems to have no effect at all. Even if I remove it, there're still some routes with CORS enabled.There seems to be some CORS configurations on
swagger-node-runner
, but I was unable to figure out how it should work. Could you give me some pointers?