Skip to content

Commit 1828f68

Browse files
committed
Allow for the configuration of Access-Control-Allow-Origin
Signed-off-by: Elijah Zupancic <[email protected]>
1 parent 28824ad commit 1828f68

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

common/docker-entrypoint.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ else
5050
export LIMIT_METHODS_TO_CSV="GET, HEAD"
5151
fi
5252

53+
if [ -z "${CORS_ALLOWED_ORIGIN+x}" ]; then
54+
export CORS_ALLOWED_ORIGIN="*"
55+
fi
56+
5357
# Nothing is modified under this line
5458

5559
if [ -z "${NGINX_ENTRYPOINT_QUIET_LOGS:-}" ]; then

common/etc/nginx/templates/gateway/cors.conf.template

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
set $request_cors "${request_method}_${CORS_ENABLED}";
22

33
if ($request_cors = "OPTIONS_1") {
4-
add_header 'Access-Control-Allow-Origin' '*';
4+
add_header 'Access-Control-Allow-Origin' '${CORS_ALLOWED_ORIGIN}';
55
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
66
#
77
# Custom headers and headers various browsers *should* be OK with but aren't
@@ -17,14 +17,14 @@ if ($request_cors = "OPTIONS_1") {
1717
}
1818

1919
if ($request_cors = "GET_1") {
20-
add_header 'Access-Control-Allow-Origin' '*' always;
20+
add_header 'Access-Control-Allow-Origin' '${CORS_ALLOWED_ORIGIN}' always;
2121
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
2222
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
2323
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
2424
}
2525

2626
if ($request_cors = "HEAD_1") {
27-
add_header 'Access-Control-Allow-Origin' '*' always;
27+
add_header 'Access-Control-Allow-Origin' '${CORS_ALLOWED_ORIGIN}' always;
2828
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
2929
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
3030
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;

docs/getting_started.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ running as a Container or as a Systemd service.
4545
[this example](https://enable-cors.org/server_nginx.html).
4646
CORS settings can be fine-tuned by overwriting the
4747
[`cors.conf.template`](/common/etc/nginx/templates/gateway/cors.conf.template) file. (default: false)
48+
* `CORS_ALLOWED_ORIGIN` - (optional) value to set to be returned from the
49+
CORS `Access-Control-Allow-Origin` header. This value is only used if
50+
CORS is enabled. (default: *)
4851

4952
If you are using [AWS instance profile credentials](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_switch-role-ec2.html),
5053
you will need to omit the `S3_ACCESS_KEY_ID` and `S3_SECRET_KEY` variables from

0 commit comments

Comments
 (0)