improvement(docker): avoid caching mounted json/yml/yaml assets (via #5151)
This commit is contained in:
@@ -13,7 +13,7 @@ ENV SWAGGER_JSON "/app/swagger.json"
|
|||||||
ENV PORT 8080
|
ENV PORT 8080
|
||||||
ENV BASE_URL ""
|
ENV BASE_URL ""
|
||||||
|
|
||||||
COPY ./docker/nginx.conf /etc/nginx/
|
COPY ./docker/nginx.conf ./docker/cors.conf /etc/nginx/
|
||||||
|
|
||||||
# copy swagger files to the `/js` folder
|
# copy swagger files to the `/js` folder
|
||||||
COPY ./dist/* /usr/share/nginx/html/
|
COPY ./dist/* /usr/share/nginx/html/
|
||||||
|
|||||||
14
docker/cors.conf
Normal file
14
docker/cors.conf
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
add_header 'Access-Control-Allow-Origin' '*' always;
|
||||||
|
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
|
||||||
|
#
|
||||||
|
# Custom headers and headers various browsers *should* be OK with but aren't
|
||||||
|
#
|
||||||
|
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type' always;
|
||||||
|
#
|
||||||
|
# Tell client that this pre-flight info is valid for 20 days
|
||||||
|
#
|
||||||
|
add_header 'Access-Control-Max-Age' $access_control_max_age always;
|
||||||
|
|
||||||
|
if ($request_method = OPTIONS) {
|
||||||
|
return 204;
|
||||||
|
}
|
||||||
@@ -12,6 +12,10 @@ http {
|
|||||||
|
|
||||||
keepalive_timeout 65;
|
keepalive_timeout 65;
|
||||||
|
|
||||||
|
map $request_method $access_control_max_age {
|
||||||
|
OPTIONS 1728000; # 20 days
|
||||||
|
}
|
||||||
|
|
||||||
server {
|
server {
|
||||||
listen 8080;
|
listen 8080;
|
||||||
server_name localhost;
|
server_name localhost;
|
||||||
@@ -19,32 +23,15 @@ http {
|
|||||||
|
|
||||||
location / {
|
location / {
|
||||||
alias /usr/share/nginx/html/;
|
alias /usr/share/nginx/html/;
|
||||||
|
expires 1d;
|
||||||
|
|
||||||
if ($request_method = 'OPTIONS') {
|
location ~* \.(?:json|yml|yaml)$ {
|
||||||
add_header 'Access-Control-Allow-Origin' '*';
|
expires -1;
|
||||||
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
|
|
||||||
#
|
include cors.conf;
|
||||||
# Custom headers and headers various browsers *should* be OK with but aren't
|
|
||||||
#
|
|
||||||
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
|
|
||||||
#
|
|
||||||
# Tell client that this pre-flight info is valid for 20 days
|
|
||||||
#
|
|
||||||
add_header 'Access-Control-Max-Age' 1728000;
|
|
||||||
add_header 'Content-Type' 'text/plain charset=UTF-8';
|
|
||||||
add_header 'Content-Length' 0;
|
|
||||||
return 204;
|
|
||||||
}
|
|
||||||
if ($request_method = 'POST') {
|
|
||||||
add_header 'Access-Control-Allow-Origin' '*';
|
|
||||||
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
|
|
||||||
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
|
|
||||||
}
|
|
||||||
if ($request_method = 'GET') {
|
|
||||||
add_header 'Access-Control-Allow-Origin' '*';
|
|
||||||
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
|
|
||||||
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
include cors.conf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ replace_or_delete_in_index () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if [ "${BASE_URL}" ]; then
|
if [ "${BASE_URL}" ]; then
|
||||||
sed -i "s|location .* {|location $BASE_URL {|g" /etc/nginx/nginx.conf
|
sed -i "s|location / {|location $BASE_URL {|g" /etc/nginx/nginx.conf
|
||||||
fi
|
fi
|
||||||
|
|
||||||
replace_in_index myApiKeyXXXX123456789 $API_KEY
|
replace_in_index myApiKeyXXXX123456789 $API_KEY
|
||||||
|
|||||||
Reference in New Issue
Block a user