|
|
@@ -13,6 +13,7 @@ const path_1 = __importDefault(require("path"));
|
|
|
const apiRoutes_1 = __importDefault(require("./routes/apiRoutes"));
|
|
|
const clickhouseService_1 = require("./services/clickhouseService");
|
|
|
const database_1 = require("./database");
|
|
|
+const morgan_1 = __importDefault(require("morgan"));
|
|
|
const app = (0, express_1.default)();
|
|
|
const port = process.env.PORT || 3000;
|
|
|
const mongoUri = process.env.MONGO_URI || "mongodb://oms:oms123.@localhost:27717/omsdb?authSource=admin";
|
|
|
@@ -46,25 +47,12 @@ redisClient.on("error", (err) => console.error("Redis connection error:", err));
|
|
|
}
|
|
|
})();
|
|
|
// Middleware
|
|
|
+// 服务部署在反向代理(如 Nginx)后面,需设置此项以正确获取客户端 IP
|
|
|
+app.set("trust proxy", true);
|
|
|
+// 👈 新增:使用 morgan 中间件来记录所有请求
|
|
|
+// :remote-addr 和 :req[host] 会通过 app.set("trust proxy", true) 正常工作
|
|
|
+app.use((0, morgan_1.default)('[:date[clf]] :remote-addr :req[host] :status :response-time ms :res[content-length] ":method :url HTTP/:http-version" ":referrer" ":user-agent"'));
|
|
|
app.use(express_1.default.json());
|
|
|
-// 新增中间件:为每个API请求添加日志打印
|
|
|
-app.use((req, res, next) => {
|
|
|
- console.log(`[API Request] ${new Date().toISOString()} - ${req.method} ${req.originalUrl}`);
|
|
|
- next();
|
|
|
-});
|
|
|
-// --- 在这里添加全局禁用缓存的中间件 ---
|
|
|
-// app.use("/api", (req: Request, res: Response, next: NextFunction) => {
|
|
|
-// // 为所有 API 路由显式禁用浏览器缓存
|
|
|
-// res.set({
|
|
|
-// "Cache-Control": "no-cache, no-store, must-revalidate",
|
|
|
-// Pragma: "no-cache",
|
|
|
-// Expires: "0",
|
|
|
-// ETag: null, // 移除ETag以强制浏览器重新验证
|
|
|
-// "Last-Modified": null, // 移除Last-Modified以强制浏览器重新验证
|
|
|
-// });
|
|
|
-// next();
|
|
|
-// });
|
|
|
-// ------------------------------------
|
|
|
// API routes
|
|
|
app.use("/api", apiRoutes_1.default);
|
|
|
// 动态设置公共目录和Angular应用路径
|