dinghy-http-proxy icon indicating copy to clipboard operation
dinghy-http-proxy copied to clipboard

Add CORS Support

Open scotthelm opened this issue 8 years ago • 4 comments
trafficstars

I am using docker-compose for a web API. I am developing a javascript front-end in a separate docker-compose project. I found that CORS was not enabled for the API endpoint. In a fork, I have added support for CORS to the nginx.tmpl. I am now able to reach the API from the front-end via CORS enabled xhr request.

I have a PR ready if you would like to consider adding CORS support.

scotthelm avatar Mar 19 '17 18:03 scotthelm

I've found that we typically end up setting the CORS headers in our apps, not in a of web proxy, so that we have more dynamic control over how the headers are generated. Adding CORS support in this proxy sounds good, but we'll want it optional behind an environment variable or some other means, since enabling it by default would interfere with testing app-defined CORS functionality.

codekitchen avatar Mar 20 '17 15:03 codekitchen

I have added a conditional check for a container's CORS_ENABLED environment variable. If present and parsed as true, then the CORS block will be enabled for that container's config.

e.g.

// docker-compose.yml
...
services:
  api:
    environment:
      - CORS_ENABLED=true
  web:
    environment:
      - ...

would enable CORS for api nginx config, while leaving CORS headers off web nginx config

scotthelm avatar Mar 20 '17 19:03 scotthelm

sweet, sounds great. please add something to the configuration section of the README when you send over the PR, as well. thanks!

codekitchen avatar Mar 20 '17 20:03 codekitchen

I have added #29

scotthelm avatar Mar 20 '17 20:03 scotthelm