【问题标题】:Setting custom directory for server files for Next.js为 Next.js 的服务器文件设置自定义目录
【发布时间】:2019-04-11 10:57:08
【问题描述】:

我想将所有与后端相关的文件保存在名为“服务器”的文件夹中,而不是在根目录中。现在的问题是前端无法正确加载,因为它找不到“页面”目录。我记得有一种方法可以在初始化应用程序时以某种方式设置目录,但我不记得具体细节了。有人可以帮我解决这个问题吗?

服务器/index.js:

const express = require('express')
const next = require('next')
const dev = process.env.NODE_ENV !== 'production'
const app = next({ 
  dev, 
  // some config property that I don't remember
})
app.prepare().then(() => {
    const server = express()
    server.listen(3000, () => console.log('> Ready on http://localhost:3000'))
})

【问题讨论】:

    标签: javascript reactjs next.js


    【解决方案1】:

    您可以阅读documentation

    The next API is as follows:
    
    next(opts: object)
    Supported options:
    
    dev (bool) whether to launch Next.js in dev mode - default false
    dir (string) where the Next project is located - default '.'
    quiet (bool) Hide error messages containing server information - default false
    conf (object) the same object you would use in next.config.js - default {}
    
    Then, change your start script to NODE_ENV=production node server.js.
    

    dir 选项。

    【讨论】:

    • 感谢您的回答!我不知何故跳过了文档的那部分。
    猜你喜欢
    • 2020-08-31
    • 1970-01-01
    • 2017-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-04
    • 1970-01-01
    相关资源
    最近更新 更多