我正在使用next.js 9.5.x,我正在寻找一种通过next.config.js配置主机名和端口的方法。我已经搜索了有关这方面的文档,但没有找到这个主题的答案。
我已经在.env文件中读取了一系列next.config.js文件,用于设置serval内容,并将一些环境变量传递给应用程序代码本身。我已经得到了一些指定主机名和端口的环境变量,并希望重用它们来设置服务器/开发服务器的主机名和端口。
我找到的唯一两个解决方案,用于更改这两个参数,是next的命令行设置,或具有自定义的server.js。目前,我正在使用自定义server.js,并且在内部再次读取所有.env文件,只是为了安装端口和主机名。
我想摆脱server.js,因为我认为必须有一种通过next.config.js文件来配置它的方法,反正我已经有了,而且一切都已经就绪。
谢谢你提供有关这方面的一些信息。
发布于 2021-02-03 03:54:57
更改端口的:
在package.josn
中,=>脚本=>添加" dev ":"next dev -p 5500__“
"scripts": {
"dev": "next dev -p 5500",
"build": "next build",
"start": "next start"
}
*我找不到如何更改主机名.
发布于 2022-09-22 10:32:17
您可以使用-H
来指定主机。这是来自next dev的帮助消息:
Description
Starts the application in development mode (hot-code reloading, error
reporting, etc)
Usage
$ next dev <dir> -p <port number>
<dir> represents the directory of the Next.js application.
If no directory is provided, the current directory will be used.
Options
--port, -p A port number on which to start the application
--hostname, -H Hostname on which to start the application (default: 0.0.0.0)
--help, -h Displays this message
https://stackoverflow.com/questions/63753307
复制相似问题