是否可以在不使用自定义服务器或包装器处理程序的情况下使用中间件创建Next.js应用程序?
当我创建一个Express应用程序时,我将代码分成不同的require语句,调用Express中间件:
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中使用中间件一篇文章,但它使用了我想要避免的包装解决方案。
发布于 2020-08-10 06:45:57
目前,Next.js只支持中器路径。目前还不支持常规页面路径中的中间件。
https://stackoverflow.com/questions/63297913
复制相似问题