gpt4 book ai didi

node.js - 在 Azure Web App 上的 iisnode 上运行 Next.js 时出现问题

转载 作者:太空宇宙 更新时间:2023-11-03 22:50:25 27 4
gpt4 key购买 nike

尝试在 Azure Web App 上部署并运行 Next.js。 Azure Web App 在仅与 Express.js 一起运行时可以工作,但一旦我调用 nex() 它就会失败。尝试在 Azure 门户中启用错误日志记录,但没有太多用处,只有一般的 500 错误。

以下是有效和无效的方法。

作品:

var express = require('express');
var expressServer = express();

expressServer.get('/', function (req, res) {
res.send('Express is working on IISNode!');
});

expressServer.listen(process.env.PORT || 8080);

不起作用:

var express = require('express');
const next = require('next');
var expressServer = express();
var app = next();

expressServer.get('/', function (req, res) {
res.send('Express is working on IISNode!');
});

expressServer.listen(process.env.PORT || 8080);

此时我什至懒得获取请求处理程序,因为 app = next() 失败了。

包.json:

"engines": {
"node": "9.4.0 || 8.9.x"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.16.2",
"next": "^4.2.3",
"next-redux-wrapper": "^1.3.5",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-redux": "^5.0.6",
"redux": "^3.7.2",
"redux-thunk": "^2.2.0"
},
"devDependencies": {
"babel-preset-es2015": "^6.24.1",
"babel-preset-stage-2": "^6.24.1",
"nodemon": "^1.14.11"
}

编辑:我认为问题在于 next build 需要首先运行。我正在寻找是否可以使用 Kudu 之类的命令添加一些部署后/构建命令。如果您有任何建议,请告诉我。

最佳答案

你是对的,你需要先运行下一个构建

因此,如果您在项目根目录下创建 pages 目录并编辑 package.json 添加以下内容,这将在 Azure Web App 中起作用:

"scripts": {
"postinstall": "next build"
}

关于node.js - 在 Azure Web App 上的 iisnode 上运行 Next.js 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48450837/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com