无法使Azure应用服务上运行的Next.js应用运行

时间:2019-01-07 17:57:19

标签: node.js azure azure-web-sites next.js

我正在尝试在Azure应用服务(URL为https://asmkp-rich-test2.azurewebsites.net/)中运行最基本的Next.js应用。

我可以从git部署一个正常运行的基本Node应用程序(存储库位于https://github.com/Richiban/nextjs-azure-test,分支为release)。

但是,我什么也不会让此应用程序运行。

如果您点击该URL,您将看到:

The page cannot be displayed because an internal server error has occurred.

除了以下内容外,std输出中没有任何内容:

Node version: v10.6.0
Done
[5:45:37 PM] Compiling server
[5:45:38 PM] Compiling client
[5:45:38 PM] Compiled server in 1000ms
[5:45:41 PM] Compiled client in 3s
 DONE  Compiled successfully in 3859ms5:45:41 PM

App prepared
Got handle
Ready on http://localhost:8080

,错误输出中没有任何内容,除了:

(node:22980) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.

您可以在git repo中看到我的server.js,但为了方便阅读,我还将在此处包括它:

const http = require("http");
const next = require("next");
const port = parseInt(process.env.PORT, 10) || 3000;
const dev = process.env.NODE_ENV !== "production";
const app = next({ dev });

console.log("Node version: " + process.version);

app.prepare()
    .then(() => {
        console.log("App prepared");

        const handle = app.getRequestHandler();

        console.log("Got handle");

        http.createServer(function(req, res) {
            console.log(`Processing incoming request`);

            try {
                handle(req, res).catch(function(e) {
                    console.log(`Error caught3: ` + e);
                    console.log(e);
                });
                
                console.log(`Incoming request done`);
            } catch (e) {
                console.log(`Error caught: ` + e);
                console.log(e);
            }
        }).listen(port);

        console.log(`> Ready on http://localhost:${port}`);
    })
    .catch(function(e) {
        console.log(`Error caught2: ` + e);
        console.log(e);
    });

console.log("Done");

从您可能已经看到的日志数量中您可以看到,今天我已经不知所措了。

因此,总而言之,我拥有与Git一起部署到Azure应用服务的最简单的Next.js应用,尽管它在我的计算机上运行得很好,但在Azure中我却收到了一条毫无意义的错误消息:看起来根本没有更多细节。

请帮助。

1 个答案:

答案 0 :(得分:1)

DeprecationWarning是一个红色鲱鱼。您看到此一般错误,因为iisnode无法与节点进程通信。

process.env.PORT实际上是使用iisnode时的管道名称,因此会导致parseInt失败并使用您的后备端口3000。这意味着您的next.js应用程序正在侦听错误的端口。更新您要相应设置端口号的行:

const port = process.env.PORT;

相关问题