【发布时间】:2019-06-02 09:57:40
【问题描述】:
我正在尝试让最基本的 Next.js 应用在 Azure 应用服务中运行(URL 是 https://asmkp-rich-test2.azurewebsites.net/)。
我可以让一个基本的 Node 应用程序运行良好,从 git 部署(存储库在这里: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 存储库中查看我的 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");
正如您可能从我塞在那里的日志数量中看到的那样,我今天对此束手无策。
所以,总而言之,我有一个最简单的 Next.js 应用程序,我正在使用 Git 将它部署到 Azure 应用程序服务,虽然它在我的机器上运行得很好,但在 Azure 中我收到一条毫无意义的错误消息看起来根本没有更多细节。
请帮忙。
【问题讨论】:
-
也许可以尝试使用 express github.com/zeit/next.js/blob/master/examples/… 部署自定义 server.js 并查看它是否有效
-
@iurii 你能想到为什么从内置服务器切换到 Express 会有帮助吗?我的意思是,无论如何我都愿意试一试......
-
不是真的,但我不明白为什么它一开始就不起作用:(所以只是给你一个我头脑中的建议。
标签: node.js azure azure-web-app-service next.js