是否可以在不使用自定義服務器或包裝器處理程序的情況下使用中間件創建 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 中使用中間件,但它使用了我想避免的包裝器解決方案。
Next.js:沒有自定義服務器或包裝器的中間件
皈依舞
2022-12-22 15:11:48