【问题标题】:Next.js Express Custom Server { dev: true } loads forever (empty response) but production { dev: false } worksNext.js Express 自定义服务器 { dev: true } 永远加载(空响应)但生产 { dev: false } 有效
【发布时间】:2021-06-18 15:14:35
【问题描述】:

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

我在/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 文件夹位于根目录中。

谢谢。

【问题讨论】:

    标签: javascript node.js reactjs express next.js


    【解决方案1】:

    我发现了错误。

    我忘了打app.prepare()

    app.prepare().then(() => {
    
    // add handle to router/app after app.prepare has finished
    
    })
    

    【讨论】:

      猜你喜欢
      • 2020-08-26
      • 2020-04-08
      • 2018-01-21
      • 1970-01-01
      • 1970-01-01
      • 2017-05-22
      • 2021-07-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多