Javascript Next.js:没有自定义服务器或包装器的中间件

Javascript Next.js:没有自定义服务器或包装器的中间件,javascript,node.js,next.js,Javascript,Node.js,Next.js,是否可以使用中间件创建Next.js应用程序,而无需使用自定义服务器或包装处理程序 创建Express应用程序时,我将代码拆分为不同的require语句,调用Express Middleware: const express = require("express"); const app = express(); // I call the functions in each modules to use the different middlewares require(

是否可以使用中间件创建Next.js应用程序,而无需使用自定义服务器或包装处理程序

创建Express应用程序时,我将代码拆分为不同的require语句,调用Express Middleware:

const express = require("express");
const app = express();

// I call the functions in each modules to use the different middlewares
require("./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仅支持api路径。在常规页面路径中还不支持中间件