Spaces:
Paused
Paused
Commit ·
20b90e8
1
Parent(s): eaf85b2
修复: 更新端口配置为7860并添加详细日志
Browse files- Dockerfile +10 -2
- server.js +30 -2
Dockerfile
CHANGED
|
@@ -5,6 +5,11 @@ FROM node:20-slim
|
|
| 5 |
# 设置工作目录
|
| 6 |
WORKDIR /code
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
# Copy package.json and package-lock.json to the container
|
| 9 |
COPY package.json package-lock.json ./
|
| 10 |
|
|
@@ -15,7 +20,10 @@ COPY . .
|
|
| 15 |
RUN npm install
|
| 16 |
|
| 17 |
# Build the application
|
| 18 |
-
RUN
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
# Set environment variables
|
| 21 |
ENV NODE_ENV=production
|
|
@@ -25,4 +33,4 @@ ENV APP_PORT=7860
|
|
| 25 |
EXPOSE 7860
|
| 26 |
|
| 27 |
# Start the application
|
| 28 |
-
CMD ["
|
|
|
|
| 5 |
# 设置工作目录
|
| 6 |
WORKDIR /code
|
| 7 |
|
| 8 |
+
# 设置环境变量
|
| 9 |
+
ENV NODE_ENV=production
|
| 10 |
+
ENV APP_PORT=7860
|
| 11 |
+
ENV DEBUG=true
|
| 12 |
+
|
| 13 |
# Copy package.json and package-lock.json to the container
|
| 14 |
COPY package.json package-lock.json ./
|
| 15 |
|
|
|
|
| 20 |
RUN npm install
|
| 21 |
|
| 22 |
# Build the application
|
| 23 |
+
RUN echo "===== 开始构建应用 =====" && \
|
| 24 |
+
npm run build && \
|
| 25 |
+
echo "===== 构建完成 =====" && \
|
| 26 |
+
ls -la dist/
|
| 27 |
|
| 28 |
# Set environment variables
|
| 29 |
ENV NODE_ENV=production
|
|
|
|
| 33 |
EXPOSE 7860
|
| 34 |
|
| 35 |
# Start the application
|
| 36 |
+
CMD ["node", "server.js"]
|
server.js
CHANGED
|
@@ -3,6 +3,7 @@ import path from "path";
|
|
| 3 |
import { fileURLToPath } from "url";
|
| 4 |
import dotenv from "dotenv";
|
| 5 |
import cookieParser from "cookie-parser";
|
|
|
|
| 6 |
import {
|
| 7 |
createRepo,
|
| 8 |
uploadFiles,
|
|
@@ -25,6 +26,16 @@ import { COLORS } from "./utils/colors.js";
|
|
| 25 |
// Load environment variables from .env file
|
| 26 |
dotenv.config();
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
const app = express();
|
| 29 |
|
| 30 |
const ipAddresses = new Map();
|
|
@@ -32,7 +43,8 @@ const ipAddresses = new Map();
|
|
| 32 |
const __filename = fileURLToPath(import.meta.url);
|
| 33 |
const __dirname = path.dirname(__filename);
|
| 34 |
|
| 35 |
-
|
|
|
|
| 36 |
const REDIRECT_URI =
|
| 37 |
process.env.REDIRECT_URI || `http://localhost:${PORT}/auth/login`;
|
| 38 |
const MODEL_ID = process.env.DEFAULT_MODEL_ID || "deepseek-ai/DeepSeek-V3-0324";
|
|
@@ -568,5 +580,21 @@ app.get("*", (_req, res) => {
|
|
| 568 |
});
|
| 569 |
|
| 570 |
app.listen(PORT, () => {
|
| 571 |
-
console.log(`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 572 |
});
|
|
|
|
| 3 |
import { fileURLToPath } from "url";
|
| 4 |
import dotenv from "dotenv";
|
| 5 |
import cookieParser from "cookie-parser";
|
| 6 |
+
import fs from "fs"; // 使用 ESM 语法导入 fs 模块
|
| 7 |
import {
|
| 8 |
createRepo,
|
| 9 |
uploadFiles,
|
|
|
|
| 26 |
// Load environment variables from .env file
|
| 27 |
dotenv.config();
|
| 28 |
|
| 29 |
+
// 打印环境变量(排除敏感信息)
|
| 30 |
+
console.log('===== 环境变量 =====');
|
| 31 |
+
console.log('NODE_ENV:', process.env.NODE_ENV);
|
| 32 |
+
console.log('APP_PORT:', process.env.APP_PORT);
|
| 33 |
+
console.log('DEFAULT_MODEL_ID:', process.env.DEFAULT_MODEL_ID);
|
| 34 |
+
console.log('REDIRECT_URI:', process.env.REDIRECT_URI);
|
| 35 |
+
console.log('OPENAI_COMPATIBLE_ENDPOINT:', process.env.OPENAI_COMPATIBLE_ENDPOINT ? '已设置' : '未设置');
|
| 36 |
+
console.log('OPENAI_COMPATIBLE_MODEL_ID:', process.env.OPENAI_COMPATIBLE_MODEL_ID);
|
| 37 |
+
console.log('===================');
|
| 38 |
+
|
| 39 |
const app = express();
|
| 40 |
|
| 41 |
const ipAddresses = new Map();
|
|
|
|
| 43 |
const __filename = fileURLToPath(import.meta.url);
|
| 44 |
const __dirname = path.dirname(__filename);
|
| 45 |
|
| 46 |
+
// Hugging Face Spaces 使用 7860 端口
|
| 47 |
+
const PORT = process.env.APP_PORT || 7860;
|
| 48 |
const REDIRECT_URI =
|
| 49 |
process.env.REDIRECT_URI || `http://localhost:${PORT}/auth/login`;
|
| 50 |
const MODEL_ID = process.env.DEFAULT_MODEL_ID || "deepseek-ai/DeepSeek-V3-0324";
|
|
|
|
| 580 |
});
|
| 581 |
|
| 582 |
app.listen(PORT, () => {
|
| 583 |
+
console.log(`===== 应用启动信息 =====`);
|
| 584 |
+
console.log(`启动时间: ${new Date().toISOString()}`);
|
| 585 |
+
console.log(`运行环境: ${process.env.NODE_ENV || 'development'}`);
|
| 586 |
+
console.log(`服务器启动在端口: ${PORT}`);
|
| 587 |
+
console.log(`默认模型: ${MODEL_ID}`);
|
| 588 |
+
console.log(`静态文件目录: ${path.join(__dirname, "dist")}`);
|
| 589 |
+
|
| 590 |
+
// 检查静态文件是否存在
|
| 591 |
+
const indexPath = path.join(__dirname, "dist", "index.html");
|
| 592 |
+
if (fs.existsSync(indexPath)) {
|
| 593 |
+
console.log(`index.html 文件存在: ${indexPath}`);
|
| 594 |
+
} else {
|
| 595 |
+
console.error(`错误: index.html 文件不存在: ${indexPath}`);
|
| 596 |
+
console.log(`目录内容: ${fs.readdirSync(path.join(__dirname, "dist")).join(', ') || '空目录'}`);
|
| 597 |
+
}
|
| 598 |
+
|
| 599 |
+
console.log(`=======================`);
|
| 600 |
});
|