2025-08-25 17:11:15 +08:00
|
|
|
import dotenv from "dotenv";
|
|
|
|
|
import express from "express";
|
|
|
|
|
import cors from "cors";
|
|
|
|
|
import compression from "compression";
|
|
|
|
|
import nocache from "nocache";
|
|
|
|
|
import path from "path";
|
|
|
|
|
|
|
|
|
|
dotenv.config({ path: path.resolve(__dirname, "../../../.env") });
|
|
|
|
|
|
|
|
|
|
import "./database";
|
2025-09-26 15:50:37 +08:00
|
|
|
import { sequelize } from "./database/instance";
|
|
|
|
|
import {errorHandler} from "./middleware/errorHandler";
|
2025-09-26 16:10:53 +08:00
|
|
|
import {RegisterTsoaRoutes} from "./middleware/tsoa.middleware"; // tsoa 生成的
|
2025-08-25 17:11:15 +08:00
|
|
|
|
|
|
|
|
const port = process.env.PORT || 3005;
|
|
|
|
|
|
|
|
|
|
const app = express();
|
|
|
|
|
app.set("etag", false);
|
|
|
|
|
app.use(nocache());
|
|
|
|
|
app.use(cors());
|
|
|
|
|
app.use(express.json({ limit: "100mb" }));
|
|
|
|
|
app.use(compression());
|
|
|
|
|
app.use(express.static(path.resolve(__dirname, "client")));
|
|
|
|
|
|
2025-09-26 12:20:02 +08:00
|
|
|
// Register tsoa routes
|
2025-09-26 16:10:53 +08:00
|
|
|
RegisterTsoaRoutes(app);
|
2025-09-26 15:50:37 +08:00
|
|
|
|
|
|
|
|
app.use(errorHandler);
|
2025-08-25 17:11:15 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
const host = "0.0.0.0";
|
2025-09-12 11:01:39 +08:00
|
|
|
app.listen(Number(port), host, async () => {
|
|
|
|
|
try {
|
|
|
|
|
await sequelize.sync({ alter: true });
|
2025-09-12 16:03:27 +08:00
|
|
|
console.log("[server]: sequelize.sync() executed");
|
2025-09-12 11:01:39 +08:00
|
|
|
} catch (e) {
|
2025-09-12 16:03:27 +08:00
|
|
|
console.error("Failed to sync database:", e);
|
2025-09-12 11:01:39 +08:00
|
|
|
}
|
2025-08-25 17:11:15 +08:00
|
|
|
console.log(`[server]: Server is running at http://${host}:${port}`);
|
|
|
|
|
});
|