Skip to content

Commit dd34393

Browse files
segevfinershockey
authored andcommitted
improvement(docker): avoid caching mounted json/yml/yaml assets (via #5151)
1 parent 455ec3d commit dd34393

File tree

4 files changed

+27
-26
lines changed

4 files changed

+27
-26
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ ENV SWAGGER_JSON "/app/swagger.json"
1313
ENV PORT 8080
1414
ENV BASE_URL ""
1515

16-
COPY ./docker/nginx.conf /etc/nginx/
16+
COPY ./docker/nginx.conf ./docker/cors.conf /etc/nginx/
1717

1818
# copy swagger files to the `/js` folder
1919
COPY ./dist/* /usr/share/nginx/html/

docker/cors.conf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
add_header 'Access-Control-Allow-Origin' '*' always;
2+
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
3+
#
4+
# Custom headers and headers various browsers *should* be OK with but aren't
5+
#
6+
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type' always;
7+
#
8+
# Tell client that this pre-flight info is valid for 20 days
9+
#
10+
add_header 'Access-Control-Max-Age' $access_control_max_age always;
11+
12+
if ($request_method = OPTIONS) {
13+
return 204;
14+
}

docker/nginx.conf

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,26 @@ http {
1212

1313
keepalive_timeout 65;
1414

15+
map $request_method $access_control_max_age {
16+
OPTIONS 1728000; # 20 days
17+
}
18+
1519
server {
1620
listen 8080;
1721
server_name localhost;
1822
index index.html index.htm;
1923

2024
location / {
2125
alias /usr/share/nginx/html/;
26+
expires 1d;
2227

23-
if ($request_method = 'OPTIONS') {
24-
add_header 'Access-Control-Allow-Origin' '*';
25-
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
26-
#
27-
# Custom headers and headers various browsers *should* be OK with but aren't
28-
#
29-
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
30-
#
31-
# Tell client that this pre-flight info is valid for 20 days
32-
#
33-
add_header 'Access-Control-Max-Age' 1728000;
34-
add_header 'Content-Type' 'text/plain charset=UTF-8';
35-
add_header 'Content-Length' 0;
36-
return 204;
37-
}
38-
if ($request_method = 'POST') {
39-
add_header 'Access-Control-Allow-Origin' '*';
40-
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
41-
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
42-
}
43-
if ($request_method = 'GET') {
44-
add_header 'Access-Control-Allow-Origin' '*';
45-
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
46-
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
28+
location ~* \.(?:json|yml|yaml)$ {
29+
expires -1;
30+
31+
include cors.conf;
4732
}
33+
34+
include cors.conf;
4835
}
4936
}
5037
}

docker/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ replace_or_delete_in_index () {
2424
}
2525

2626
if [ "${BASE_URL}" ]; then
27-
sed -i "s|location .* {|location $BASE_URL {|g" /etc/nginx/nginx.conf
27+
sed -i "s|location / {|location $BASE_URL {|g" /etc/nginx/nginx.conf
2828
fi
2929

3030
replace_in_index myApiKeyXXXX123456789 $API_KEY

0 commit comments

Comments
 (0)