是否可以在不使用自定义服务器或包装器处理程序的情况下使用中间件创建 Next.js 应用程序?当我创建一个 Express 应用程序时,我将我的代码分成不同的 require 语句调用 Express 中间件:const express = require("express");const app = express();// I call the functions in each modules to use the different middlewaresrequire("./startup/cors")(app);require("./startup/routes")(app);require("./startup/db")();const port = process.env.PORT || config.get("port");const server = app.listen(port, () => winston.info(`Listening on port ${port}...`));module.exports = server;例如,该./startup/cors模块包含以下行:const cors = require("cors");module.exports = function(app) { app.use(cors());};但是,对于我的 Next.js 应用程序,我不明白如何在不创建自定义服务器的情况下获得这样的东西。我已经看到文章在没有自定义服务器的情况下在 Next.js 中使用中间件,但它使用了我想避免的包装器解决方案。
添加回答
举报
0/150
提交
取消