dinghy-http-proxy
dinghy-http-proxy copied to clipboard
Add CORS Support
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.
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.
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
sweet, sounds great. please add something to the configuration section of the README when you send over the PR, as well. thanks!
I have added #29