问题描述
我的 2 个主要文件夹是 CMS 和 nextjs,如下所示:
但是,当我运行 1 个文件夹时,它使用我的 localhost:3000,然后另一个文件夹也想使用相同的端口,但这不可能,因为我收到错误消息,说端口 3000 已在使用中。 基本上我想在 2 个不同的端口中运行我的 CMS 文件夹和 nextjs 文件夹。
我附上了我的launch.json代码以防万一:
{
"version": "0.2.0","configurations": [
{
"type": "node","request": "launch","name": "Launch Program","skipFiles": [
"<node_internals>/**"
],"program": "${workspaceFolder}\\nextjs\\.next\\server\\pages\\index.js"
}
]
}
解决方法
Next.js
您必须编辑 package.json
。
在脚本对象中,您将找到一个名为 dev 的属性。您可以像这样编辑它(例如:端口 3005):
"dev": "next dev -p 3005"
当您启动 npm run dev
时,您的应用程序将打开端口 3005
Strapi
在您的项目根目录添加一个 .env
文件,并添加一个带有您想要的端口的变量:
PORT=3627
在 Strapi 文档中阅读更多内容 here