feat: api routing in docker image

This commit is contained in:
DarkSky 2022-12-20 15:22:36 +08:00
parent eab0d6dc6e
commit e435dbd2cb
3 changed files with 50 additions and 32 deletions

39
.github/deployment/Caddyfile vendored Normal file
View File

@ -0,0 +1,39 @@
:80 {
root /* ./dist
file_server {
# precompressed br
}
encode {
zstd
gzip 9
}
header {
# 7 days
Cache-Control "public, max-age=86400, must-revalidate"
}
handle_path /api/* {
reverse_proxy {$API_SERVER} {
@error status 500 502 503 503
handle_response @error {
root * /dist
rewrite * /50x.html
file_server
}
}
}
@notStatic {
not path /_next/static/*
}
handle @notStatic {
header {
Cache-Control "no-cache, no-store, must-revalidate"
}
try_files {path} /index.html
}
}

View File

@ -1,5 +1,13 @@
FROM nginx:alpine FROM node:16-alpine as relocate
WORKDIR /app
COPY ./packages/app/out ./dist
COPY ./.github/deployment/Caddyfile ./Caddyfile
COPY ./packages/app/out /usr/share/nginx/html FROM caddy:2.6.2-alpine
ARG API_SERVER
WORKDIR /app
COPY --from=relocate /app .
COPY ./.github/deployment/nginx.conf /etc/nginx/conf.d/default.conf EXPOSE 80
ENV API_SERVER=$API_SERVER
CMD ["caddy", "run"]

View File

@ -1,29 +0,0 @@
server {
listen 80;
listen [::]:80;
server_name localhost;
#access_log /var/log/nginx/host.access.log main;
root /usr/share/nginx/html;
index index.html index.htm;
location /_next/static {
# 7 days
add_header Cache-Control "max-age=86400";
}
location / {
try_files $uri $uri.html /$uri /index.html
add_header Cache-Control "no-cache";
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}