修正端口到3001

This commit is contained in:
2025-09-18 23:53:15 +08:00
parent a8a7947942
commit 139245792f
5 changed files with 58 additions and 4 deletions

40
Dockerfile Normal file
View File

@@ -0,0 +1,40 @@
FROM node:18-alpine AS builder
WORKDIR /app
# 复制package.json和package-lock.json
COPY package*.json ./
# 安装依赖
RUN npm ci
# 复制所有源代码
COPY . .
# 构建前端应用
RUN npm run build
# 生产环境镜像
FROM node:18-alpine
WORKDIR /app
# 复制构建后的前端文件
COPY --from=builder /app/dist /app/dist
# 复制后端文件
COPY --from=builder /app/server /app/server
COPY --from=builder /app/package*.json /app/
# 只安装生产环境依赖
RUN npm ci --only=production
# 设置环境变量
ENV PORT=3010
ENV NODE_ENV=production
# 暴露端口
EXPOSE 3010
# 启动命令
CMD ["node", "server/index.js"]

14
docker-compose.yml Normal file
View File

@@ -0,0 +1,14 @@
version: '3.8'
services:
draw-app:
build: .
container_name: draw-app
restart: always
ports:
- "3010:3010"
volumes:
- ./server/lottery.db:/app/server/lottery.db
environment:
- NODE_ENV=production
- PORT=3010

View File

@@ -11,7 +11,7 @@ const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const app = express();
const PORT = process.env.PORT || 3001;
const PORT = process.env.PORT || 3010;
const server = createServer(app);
const io = new SocketIOServer(server, {
cors: {

View File

@@ -37,7 +37,7 @@ export interface Student {
class DatabaseService {
private static instance: DatabaseService;
private baseUrl: string = 'http://localhost:3001/api';
private baseUrl: string = 'http://localhost:3010/api';
private constructor() {
// 直接使用服务器API无需初始化本地数据库

View File

@@ -30,10 +30,10 @@ class WebSocketService {
// 获取当前主机地址和端口配置
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
const host = window.location.hostname === 'localhost' ? 'localhost' : window.location.hostname;
const port = process.env.NODE_ENV === 'production' ? window.location.port || '80' : '3001';
const port = process.env.NODE_ENV === 'production' ? window.location.port || '80' : '3010';
const socketUrl = process.env.NODE_ENV === 'production'
? `${protocol}//${host}${port !== '80' && port !== '443' ? ':' + port : ''}`
: `${protocol}//${host}:3001`;
: `${protocol}//${host}:3010`;
console.log('🔌 连接WebSocket服务器:', socketUrl, '(环境:', process.env.NODE_ENV, ')');