[英]Setting custom directory for server files for Next.js
我想將所有與后端相關的文件都保存在名為“ server”的文件夾中,而不是在根目錄中。 現在的問題是前端無法正確加載,因為它找不到'pages'目錄。 我記得在初始化應用程序時可以通過某種方式設置目錄,但是我不記得具體細節。 有人可以幫我嗎?
服務器/ 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'))
})
您可以閱讀文檔 :
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
選項。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.