简体   繁体   English

在Azure Web App的iisnode上运行Next.js的问题

[英]Issue running Next.js on iisnode on Azure Web App

Trying to deploy and run Next.js on Azure Web App. 尝试在Azure Web App上部署和运行Next.js。 Azure Web App works when running just with Express.js but as soon as I call nex() it fails. 仅与Express.js一起运行时,Azure Web App可以工作,但是一旦我调用nex()它就会失败。 Tried to enable the error logging in Azure portal but not much of any use came out, just generic 500 errors. 试图在Azure门户中启用错误日志记录,但没有太多用途,只有一般500错误。

Below is what works and what doesn't. 以下是有效的方法和无效的方法。

Works: 作品:

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);

Does not work: 不起作用:

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);

I don't even bother getting request handler at this point as the app = next() is failing. 由于app = next()失败,因此我现在甚至都不必理会请求处理程序。

Package.json: Package.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"
  }

EDIT: I believe the issue is that next build needs to run first. 编辑:我相信问题是, next build需要先运行。 I am looking if I can add some post deployment/build command with something like Kudu. 我在寻找是否可以添加诸如Kudu之类的某些post Deployment / build命令。 If you have any suggestions please let me know. 如果您有任何建议,请让我知道。

You are right, you need to run next build first. 没错,您需要先运行next build

So, this would work in Azure Web App if you create pages directory under project root and edit the package.json to add this: 因此,如果您在项目根目录下创建pages目录并编辑package.json以添加以下内容,则此方法将在Azure Web App中起作用:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM