Skip to content

Commit

Permalink
ensure non JS .gz files get needed "Content Encoding" header. make ng…
Browse files Browse the repository at this point in the history
…inx config more easily hot reloadable
  • Loading branch information
traceypooh committed Apr 9, 2024
1 parent 93a6b40 commit 5fb8d94
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ FROM nginx:alpine

WORKDIR /usr/share/nginx/html

RUN rm -f index.html

COPY default.conf /etc/nginx/conf.d/
RUN rm -f index.html && \
ln -sf /usr/share/nginx/html/default.conf /etc/nginx/conf.d/default.conf

COPY . .
16 changes: 10 additions & 6 deletions default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ server {
# see https://nginx.org/en/docs/http/ngx_http_charset_module.html for more details
charset utf-8;

root /usr/share/nginx/html;

location / {
root /usr/share/nginx/html;
index index.html index.htm;

# customizations:
Expand All @@ -29,17 +30,20 @@ server {
add_header Vary Origin;
}

# customization - like 1st location, but with `Content-Type` & `Content-Encoding` headers
location ~\.(js|wasm)\.gz$ {
root /usr/share/nginx/html;
# customization - like 1st location, but with `Content-Encoding` header
location ~ \.gz$ {
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
add_header Access-Control-Allow-Headers Accept-Encoding,Accept-Language,Authorization,Cache-Control,Content-Length,Content-Range,DNT,Pragma,Range,X-Requested-With;
add_header Vary Origin;

types { }
default_type application/javascript;
add_header Content-Encoding gzip;

location ~ \.(js|wasm)\.gz$ {
# these files additionally need specific content type
types { }
default_type application/javascript;
}
}

error_page 500 502 503 504 /50x.html;
Expand Down

0 comments on commit 5fb8d94

Please sign in to comment.