From 7fbb08194635cea9db6308371f866971ce7a8e4f Mon Sep 17 00:00:00 2001 From: AyushRanjan Date: Wed, 15 Nov 2023 16:34:16 +0530 Subject: [PATCH] TP-46224 | nginx configuered to handle cors --- entrypoint.sh | 2 ++ nginx/nginx.conf | 24 ++++++++++++++++++++++++ src/services/constants.ts | 2 +- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index e332f94..74defd0 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -8,5 +8,7 @@ sed -i "s~~${DISABLE_UNIVERSAL_AUTH}~g" /usr/share/nginx sed -i "s~CSP_HEADER~${CSP_HEADER}~g" /etc/nginx/conf.d/nginx.conf sed -i "s~~${TABLEAU_SERVER_URL}~g" /usr/share/nginx/html/config.js sed -i "s~~${JANUS_API_URL}~g" /usr/share/nginx/html/config.js +sed -i "s~JANUS_API_URL~${JANUS_API_URL}~g" /etc/nginx/conf.d/nginx.conf +sed -i "s~VPC_NAMESERVER~${VPC_NAMESERVER}~g" /etc/nginx/conf.d/nginx.conf exec "$@" diff --git a/nginx/nginx.conf b/nginx/nginx.conf index a15f8d1..1477a63 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -1,6 +1,7 @@ server { listen 8080; client_max_body_size 100M; + resolver VPC_NAMESERVER; set $csp_header CSP_HEADER; add_header Content-Security-Policy $csp_header; @@ -10,6 +11,29 @@ server { gzip_comp_level 4; gzip_types text/css application/javascript; + location ~ ^/events$ { + proxy_ssl_server_name on; + + if ($request_method = OPTIONS) { + add_header Access-Control-Allow-Origin $http_origin; + add_header Access-Control-Allow-Methods 'DELETE, GET, OPTIONS, PATCH, POST, PUT'; + add_header 'Access-Control-Allow-Headers' 'DNT,X-Realm-Id,X-Session-Token, X-Channel, Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; + add_header 'Access-Control-Max-Age' 1728000; + add_header Content-Type text/plain; + add_header Content-Length 0; + return 204; + } + + add_header Access-Control-Allow-Origin $http_origin; + add_header Access-Control-Allow-Methods 'DELETE, GET, OPTIONS, PATCH, POST, PUT'; + add_header 'Access-Control-Allow-Headers' 'DNT,X-Realm-Id,X-Session-Token, X-Channel, Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; + + set $config_service_base_url JANUS_API_URL; + proxy_read_timeout 120; + proxy_next_upstream error; + proxy_pass $config_service_base_url/events/json$1$is_args$args; + } + location / { root /usr/share/nginx/html; index index.html index.htm; diff --git a/src/services/constants.ts b/src/services/constants.ts index 6cb014c..ef18768 100644 --- a/src/services/constants.ts +++ b/src/services/constants.ts @@ -1 +1 @@ -export const JANUS_API = `${window?.config?.JANUS_API_URL}/events/json`; +export const JANUS_API = `/events`;