我正在尝试要求/运行文件夹中的所有文件但遇到问题:
内部端点:index.js;
const { Router } = require("express");
const router = Router();
router.get("/", async (req, res) => {
res.render("./../../views/home.ejs");
});
module.exports = router;
内部Core-routers(路由器)core.js;
const { readdirSync } = require("fs");
const findEndpoints = readdirSync(__dirname+"/../endpoints");
const endpoints = findEndpoints.filter((c) => c.split(".").pop() === "js");
class Routers {
constructor(app) {
this.app = app;
}
load() {
for (let i = 0; i < endpoints.length; i++) {
if (!endpoints.length) throw Error("No Endpoints Found.");
this.app.use(require(`${__dirname}/../endpoints/${endpoints[i]}`)("/"));
}
}
module.exports = Routers;
有人可以解释我如何让它加载所有端点并使它们可用