Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

feat: api routing in docker image

DarkSkye435dbd2cb86
diff --git a/.github/deployment/Caddyfile b/.github/deployment/Caddyfile
new file mode 100644
index 0000000000..d261c7aa26
--- /dev/null
+++ b/.github/deployment/Caddyfile
@@ -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
+ }
+}
diff --git a/.github/deployment/Dockerfile b/.github/deployment/Dockerfile
index 0e55124132..d163afda15 100644
--- a/.github/deployment/Dockerfile
+++ b/.github/deployment/Dockerfile
@@ -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"]
\ No newline at end of file
diff --git a/.github/deployment/nginx.conf b/.github/deployment/nginx.conf
deleted file mode 100644
index 7441f6f8f3..0000000000
--- a/.github/deployment/nginx.conf
+++ /dev/null
@@ -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;
- }
-}