mirror of
https://github.com/lyz05/danmaku.git
synced 2026-02-02 17:59:53 +08:00
refactor: Node18支持
This commit is contained in:
77
app.js
77
app.js
@@ -7,50 +7,53 @@ const compression = require('compression');
|
|||||||
// 引入环境变量
|
// 引入环境变量
|
||||||
require("dotenv")
|
require("dotenv")
|
||||||
.config();
|
.config();
|
||||||
|
|
||||||
// 引入一个个路由模块
|
|
||||||
const danmakuRouter = require("./routes/danmaku.mjs").default;
|
|
||||||
const app = express();
|
const app = express();
|
||||||
// 加载路由
|
// 引入一个个路由模块
|
||||||
app.use("/", danmakuRouter);
|
// const danmakuRouter = require("./routes/danmaku.mjs").default;
|
||||||
// 启用gzip压缩
|
async function loadRouter() {
|
||||||
app.use(compression());
|
const { default: danmakuRouter } = await import('./routes/danmaku.mjs');
|
||||||
|
app.use("/", danmakuRouter);
|
||||||
|
|
||||||
// view engine setup
|
// 启用gzip压缩
|
||||||
app.set("views", path.join(__dirname, "views"));
|
app.use(compression());
|
||||||
app.set("view engine", "ejs");
|
|
||||||
app.set("trust proxy", true);
|
|
||||||
|
|
||||||
app.use(logger("dev"));
|
// view engine setup
|
||||||
app.use(express.json());
|
app.set("views", path.join(__dirname, "views"));
|
||||||
app.use(express.urlencoded({ extended: false, validate: { trustProxy: false } }));
|
app.set("view engine", "ejs");
|
||||||
app.use(cookieParser());
|
app.set("trust proxy", true);
|
||||||
// 加载静态资源
|
|
||||||
app.use(express.static(path.join(__dirname, "public"), {maxAge: 86400*1000 }));
|
app.use(logger("dev"));
|
||||||
app.use(express.static(path.join(__dirname,"db")))
|
app.use(express.json());
|
||||||
app.use("/assets", [
|
app.use(express.urlencoded({ extended: false, validate: { trustProxy: false } }));
|
||||||
express.static(__dirname + "/node_modules/jquery/dist/",{maxAge: 86400*1000}),
|
app.use(cookieParser());
|
||||||
express.static(__dirname + "/node_modules/bootstrap/dist/",{maxAge: 86400*1000}),
|
// 加载静态资源
|
||||||
express.static(__dirname + "/node_modules/axios/dist/",{maxAge: 86400*1000}),
|
app.use(express.static(path.join(__dirname, "public"), {maxAge: 86400*1000 }));
|
||||||
express.static(__dirname + "/node_modules/leancloud-storage/dist",{maxAge: 86400*1000}),
|
app.use(express.static(path.join(__dirname,"db")))
|
||||||
]);
|
app.use("/assets", [
|
||||||
|
express.static(__dirname + "/node_modules/jquery/dist/",{maxAge: 86400*1000}),
|
||||||
|
express.static(__dirname + "/node_modules/bootstrap/dist/",{maxAge: 86400*1000}),
|
||||||
|
express.static(__dirname + "/node_modules/axios/dist/",{maxAge: 86400*1000}),
|
||||||
|
express.static(__dirname + "/node_modules/leancloud-storage/dist",{maxAge: 86400*1000}),
|
||||||
|
]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// catch 404 and forward to error handler
|
// catch 404 and forward to error handler
|
||||||
app.use(function (req, res, next) {
|
app.use(function (req, res, next) {
|
||||||
next(createError(404));
|
next(createError(404));
|
||||||
});
|
});
|
||||||
|
|
||||||
// error handler
|
// error handler
|
||||||
app.use(function (err, req, res) {
|
app.use(function (err, req, res) {
|
||||||
// set locals, only providing error in development
|
// set locals, only providing error in development
|
||||||
res.locals.message = err.message;
|
res.locals.message = err.message;
|
||||||
res.locals.error = req.app.get("env") === "development" ? err : {};
|
res.locals.error = req.app.get("env") === "development" ? err : {};
|
||||||
|
|
||||||
// render the error page
|
// render the error page
|
||||||
res.status(err.status || 500);
|
res.status(err.status || 500);
|
||||||
res.render("error");
|
res.render("error");
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
loadRouter();
|
||||||
|
|
||||||
module.exports = app;
|
module.exports = app;
|
||||||
|
|||||||
Reference in New Issue
Block a user