javascript - 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 文件夹位于根目录中。
谢谢你。
解决方案
我发现了错误。
我忘了打电话app.prepare()
app.prepare().then(() => {
// add handle to router/app after app.prepare has finished
})
推荐阅读
- rust - 如何编写具有相同类型但具有不同生命周期的变体的枚举,其中一个是“静态的?
- php - PHP的pthreads扩展中的Socket类的目的是什么
- makefile - 同一配方的多个隐式(或模式)规则
- java - 接受大写和小写字母字符
- r - 如何编写一个函数来一次重命名多个列?
- javascript - Zapier - 切片不是有效的功能?
- ios - 使用 clang xcode 9 为 iOS armv7+arm64 编译 C 代码
- java - 用于多种数据类型的 RecyclerView.Adapter
- vim - 为什么在这个 vimscript 中没有设置 '< 和 '>?
- php - 使用 AMPHP 从数组创建迭代器