修正端口到3001
This commit is contained in:
40
Dockerfile
Normal file
40
Dockerfile
Normal 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
14
docker-compose.yml
Normal 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
|
||||||
@@ -11,7 +11,7 @@ const __filename = fileURLToPath(import.meta.url);
|
|||||||
const __dirname = path.dirname(__filename);
|
const __dirname = path.dirname(__filename);
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
const PORT = process.env.PORT || 3001;
|
const PORT = process.env.PORT || 3010;
|
||||||
const server = createServer(app);
|
const server = createServer(app);
|
||||||
const io = new SocketIOServer(server, {
|
const io = new SocketIOServer(server, {
|
||||||
cors: {
|
cors: {
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ export interface Student {
|
|||||||
|
|
||||||
class DatabaseService {
|
class DatabaseService {
|
||||||
private static instance: DatabaseService;
|
private static instance: DatabaseService;
|
||||||
private baseUrl: string = 'http://localhost:3001/api';
|
private baseUrl: string = 'http://localhost:3010/api';
|
||||||
|
|
||||||
private constructor() {
|
private constructor() {
|
||||||
// 直接使用服务器API,无需初始化本地数据库
|
// 直接使用服务器API,无需初始化本地数据库
|
||||||
|
|||||||
@@ -30,10 +30,10 @@ class WebSocketService {
|
|||||||
// 获取当前主机地址和端口配置
|
// 获取当前主机地址和端口配置
|
||||||
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||||
const host = window.location.hostname === 'localhost' ? 'localhost' : window.location.hostname;
|
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'
|
const socketUrl = process.env.NODE_ENV === 'production'
|
||||||
? `${protocol}//${host}${port !== '80' && port !== '443' ? ':' + port : ''}`
|
? `${protocol}//${host}${port !== '80' && port !== '443' ? ':' + port : ''}`
|
||||||
: `${protocol}//${host}:3001`;
|
: `${protocol}//${host}:3010`;
|
||||||
|
|
||||||
console.log('🔌 连接WebSocket服务器:', socketUrl, '(环境:', process.env.NODE_ENV, ')');
|
console.log('🔌 连接WebSocket服务器:', socketUrl, '(环境:', process.env.NODE_ENV, ')');
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user