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

标签 node.js azure express iisnode next.js

尝试在 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/

相关文章:

javascript - 运行基本 Express 项目时出错

node.js - 使用 node.js、express 和 mongoose 搭建脚手架,比如 grails?

javascript - Typedoc 使用 require 语法抛出错误

azure - 如何在 Azure 应用程序见解中执行明确的声明?

azure - 使用 ARM 模板通过服务主体身份验证为 Azure 数据工厂创建 API 连接

linux - 使用 Terraform 与 A​​zure VM 的 SSH 连接

javascript - 引用错误 : firebase is not defined in firebase with nodejs

javascript - 不确定如何在 Express/MongoDB 应用程序中处理数据访问对象/层

javascript - 如何在 node.js 中获取所有 memcached 数据?

node.js - Express 静态中间件自动提供 index.html