From 28f6a6bc80e08969921fd37e988d8b2e4357185a Mon Sep 17 00:00:00 2001 From: SunWuyuan Date: Sat, 10 May 2025 15:04:17 +0800 Subject: [PATCH] Update `app.js` to use `fileURLToPath` for directory resolution and comment out unused imports. Modify Docker image reference in workflow configuration for deployment consistency. --- .github/workflows/docker-image.yml | 2 +- app.js | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 8e6f7ad..02873bf 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -36,7 +36,7 @@ jobs: with: images: | sunwuyuan/classworks - ghcr.io/ClassworksDev/ClassworksServer + ghcr.io/ZeroCatDev/ClassworksServer tags: | type=sha flavor: | diff --git a/app.js b/app.js index a6d3810..14ad738 100644 --- a/app.js +++ b/app.js @@ -1,7 +1,8 @@ -import createError from "http-errors"; +// import createError from "http-errors"; import express from "express"; -import { join } from "path"; -import cookieParser from "cookie-parser"; +import { join, dirname } from "path"; +import { fileURLToPath } from "url"; +// import cookieParser from "cookie-parser"; import logger from "morgan"; import bodyParser from "body-parser"; import errorHandler from "./middleware/errorHandler.js"; @@ -16,22 +17,23 @@ import cors from "cors"; app.options("*", cors()); app.use(cors()); -//全局变量 -global.dirname = import.meta.dirname; +// 获取当前文件的目录路径 +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); // 初始化 readme initReadme(); // view engine setup -app.set("views", join(dirname, "views")); +app.set("views", join(__dirname, "views")); app.set("view engine", "ejs"); app.use(bodyParser.urlencoded({ extended: true })); app.use(bodyParser.json()); app.use(logger("dev")); app.use(express.json()); app.use(express.urlencoded({ extended: false })); -app.use(cookieParser()); -app.use(express.static(join(dirname, "public"))); +// app.use(cookieParser()); +// app.use(express.static(join(__dirname, "public"))); // 添加请求超时处理中间件 app.use((req, res, next) => {