diff --git a/backend/Dockerfile b/backend/Dockerfile index 3ae5208..1325945 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -4,7 +4,7 @@ WORKDIR /home/node/app # Install Dependencies COPY package.json yarn.lock ./ -RUN yarn install --frozen-lockfile --no-cache +RUN yarn config set registry https://registry.npmmirror.com && yarn install --frozen-lockfile --no-cache # Copy source code COPY . . @@ -20,7 +20,7 @@ ENV NODE_ENV=production # Install Production Dependencies COPY package.json yarn.lock ./ -RUN yarn install --frozen-lockfile --no-cache --production +RUN yarn config set registry https://registry.npmmirror.com && yarn install --frozen-lockfile --no-cache --production # Copy build files COPY --from=builder /home/node/app/build ./build diff --git a/backend/src/file.ts b/backend/src/file.ts index 7e77582..4ba1a76 100644 --- a/backend/src/file.ts +++ b/backend/src/file.ts @@ -15,7 +15,7 @@ const limits = { const storage = multer.diskStorage({ destination: (req, file, cb) => { try { - const room = req.params.room; + const room = req.params.room as string; const dir = path.resolve(baseDir, room); fs.mkdirSync(dir, { recursive: true }); return cb(null, dir); @@ -29,7 +29,8 @@ const storage = multer.diskStorage({ }) const upload = multer({ storage, limits }); -router.post("/upload/:room", authenticate, upload.single("file"), (req, res) => { +const uploadSingle = upload.single("file") as unknown as express.RequestHandler; +router.post("/upload/:room", authenticate, uploadSingle, (req, res) => { const file = req.file; if (!file) { return res.status(422).send("422 Unprocessable Entity: Missing file"); diff --git a/server/backend/docker-compose.yml b/server/backend/docker-compose.yml new file mode 100644 index 0000000..28c81db --- /dev/null +++ b/server/backend/docker-compose.yml @@ -0,0 +1,15 @@ +services: + backend: + image: backend:latest + restart: always + ports: + - 20248:8888 + env_file: + - .local.env + volumes: + - /data/upload:/data/upload + +networks: + default: + name: database_default + external: true diff --git a/server/nginx/docker-compose.yml b/server/nginx/docker-compose.yml index f4f9373..fb05cac 100644 --- a/server/nginx/docker-compose.yml +++ b/server/nginx/docker-compose.yml @@ -2,8 +2,21 @@ services: nginx: image: nginx:stable-alpine ports: - - 443:443 + - "80:80" + - "443:443" restart: always volumes: - ./nginx.conf:/etc/nginx/nginx.conf - /etc/letsencrypt:/etc/letsencrypt + networks: + - backend + - database + +networks: + backend: + name: backend_default + external: true + database: + name: database_default + external: true + diff --git a/server/nginx/nginx.conf b/server/nginx/nginx.conf new file mode 100644 index 0000000..1d012ef --- /dev/null +++ b/server/nginx/nginx.conf @@ -0,0 +1,35 @@ +events { + worker_connections 1024; +} + +http { + server { + listen 80; # HTTP -> HTTPS redirect + listen [::]:80; + server_name zijingmoments.xyz; + return 301 https://$host$request_uri; + } + + server { + listen 443 ssl; # listen to IPv4, with SSL + listen [::]:443 ssl; # listen to IPv6, with SSL + + server_name zijingmoments.xyz; + + ssl_certificate /etc/letsencrypt/live/zijingmoments.xyz/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/zijingmoments.xyz/privkey.pem; + + location / { + proxy_pass http://backend:8888; + proxy_set_header Host $host; + client_max_body_size 100M; # allow large file upload + } + + location /v1/graphql { + proxy_pass http://graphql-engine:8080; + # Important: Do not add / to the end of URL, ref: https://blog.csdn.net/q1298252589/article/details/120729989 + proxy_set_header Upgrade $http_upgrade; # enable websocket + proxy_set_header Connection "upgrade"; # enable websocket + } + } +}