首页 > 解决方案 > Next.js Express 自定义服务器 { dev: true } 永远加载(空响应)但生产 { dev: false } 有效

问题描述

我正在使用带有 next.js 的快速自定义服务器。自定义服务器

我将下一个应用程序添加到路径下的路由器/custom/uibackend/next

const next = require('next')
const app = next({ dev: true, dir: './', conf: { } })

const handle = app.getRequestHandler()

module.exports = router => {
  router.all('*', (req, res) => handle(req, res))
}

如果我运行我的应用程序并在浏览器中访问路由,它会加载一段时间并返回一个空响应。
控制台中只有一个日志:
info - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5

如果我构建应用程序并将 dev 设置为 false,它会按预期工作,我可以访问路由和页面。

const app = next({ dev: false, dir: './', conf: { } })

我使用了以下 next.config.js 文件:

module.exports = {
  basePath: '/custom/uibackend/next'
}

我的 /pages 文件夹位于根目录中。

谢谢你。

标签: javascriptnode.jsreactjsexpressnext.js

解决方案


我发现了错误。

我忘了打电话app.prepare()

app.prepare().then(() => {

// add handle to router/app after app.prepare has finished

})

推荐阅读