From 31801d099105e5ae3a8574b622076e6bc994a759 Mon Sep 17 00:00:00 2001 From: Chever John Date: Thu, 21 Aug 2025 14:55:16 +0800 Subject: [PATCH] Updates application port to 3004 WHAT: Updates the application's default port from 8080 to 3004 across various Docker configurations and scripts. This includes changes to Dockerfiles, docker-compose files, and startup scripts. Also updates the vite config. WHY: Standardizes the port used by the application to 3004 for consistency and to avoid potential conflicts with other services that might be using port 8080. HOW: Modifies the `EXPOSE` directives in the Dockerfiles, the port mappings in the docker-compose files, the default port in the main application server file, the port in the vite config and the scripts that display the API URL. --- docker/Dockerfile.dev | 2 +- docker/Dockerfile.prod | 4 ++-- docker/docker-compose.dev.yml | 2 +- docker/docker-compose.prod.yml | 2 +- scripts/dev-up.sh | 2 +- scripts/prod-up.sh | 2 +- server/src/index.ts | 2 +- vite.config.ts | 5 +++-- 8 files changed, 11 insertions(+), 10 deletions(-) diff --git a/docker/Dockerfile.dev b/docker/Dockerfile.dev index cc4b00d..53fcdd9 100644 --- a/docker/Dockerfile.dev +++ b/docker/Dockerfile.dev @@ -15,7 +15,7 @@ COPY server/src ./server/src RUN cd server && npm install --build-from-source && npm run build -EXPOSE 8080 +EXPOSE 3004 CMD ["node", "server/dist/index.js"] diff --git a/docker/Dockerfile.prod b/docker/Dockerfile.prod index b082b5c..d45b008 100644 --- a/docker/Dockerfile.prod +++ b/docker/Dockerfile.prod @@ -17,10 +17,10 @@ RUN cd server && npm install --omit=dev --build-from-source COPY server/dist ./server/dist COPY dist ./frontend -ENV PORT=8080 +ENV PORT=3004 ENV DB_PATH=/data/purchase.db -EXPOSE 8080 +EXPOSE 3004 CMD ["node", "server/dist/index.js"] diff --git a/docker/docker-compose.dev.yml b/docker/docker-compose.dev.yml index eb2b9bd..3703aad 100644 --- a/docker/docker-compose.dev.yml +++ b/docker/docker-compose.dev.yml @@ -6,7 +6,7 @@ services: image: dm-purchase-api:dev platform: ${DOCKER_PLATFORM:-linux/amd64} ports: - - "8080:8080" + - "3004:3004" environment: - DB_PATH=/data/purchase.db volumes: diff --git a/docker/docker-compose.prod.yml b/docker/docker-compose.prod.yml index 5e2013e..348aac8 100644 --- a/docker/docker-compose.prod.yml +++ b/docker/docker-compose.prod.yml @@ -6,7 +6,7 @@ services: image: dm-purchase-api:prod platform: linux/amd64 ports: - - "8080:8080" + - "3004:3004" environment: - DB_PATH=/data/purchase.db volumes: diff --git a/scripts/dev-up.sh b/scripts/dev-up.sh index 4bed192..126ed52 100644 --- a/scripts/dev-up.sh +++ b/scripts/dev-up.sh @@ -37,6 +37,6 @@ fi echo "[步骤] 启动 Docker Compose (开发)" (cd "$ROOT_DIR/docker" && DOCKER_PLATFORM=${DOCKER_PLATFORM} docker compose -f docker-compose.dev.yml up -d --build) -echo "[完成] API: http://localhost:8080" +echo "[完成] API: http://localhost:3004" diff --git a/scripts/prod-up.sh b/scripts/prod-up.sh index 7fe43d0..1413573 100644 --- a/scripts/prod-up.sh +++ b/scripts/prod-up.sh @@ -16,6 +16,6 @@ fi echo "[步骤] 启动 Docker Compose (生产)" (cd "$ROOT_DIR/docker" && docker compose -f docker-compose.prod.yml up -d --build) -echo "[完成] API: http://localhost:8080" +echo "[完成] API: http://localhost:3004" diff --git a/server/src/index.ts b/server/src/index.ts index 2dc8efa..91e1177 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -178,7 +178,7 @@ app.patch('/api/items/:id/purchased', (req, res) => { res.json({ ok: true }); }); -const port = Number(process.env.PORT || 8080); +const port = Number(process.env.PORT || 3004); // Serve prebuilt frontend when present (production) const frontendDir = path.resolve(process.cwd(), 'frontend'); if (fs.existsSync(frontendDir)) { diff --git a/vite.config.ts b/vite.config.ts index b8d33a6..cd1f374 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -11,13 +11,14 @@ export default defineConfig({ }, }, server: { + port: 3003, proxy: { '/api': { - target: 'http://localhost:8080', + target: 'http://localhost:3004', changeOrigin: true, }, '/health': { - target: 'http://localhost:8080', + target: 'http://localhost:3004', changeOrigin: true, } }