Reputation: 161
I would be glad for any tips on how to debug this?
next.js standalone on node.js 18.19.1 on windows Azure Web App.
The app starts locally (via the /build/standalone folde )
package.json has a : "start": "node server.js"
The port 3000 indicates that process.env.PORT is not set by azure?
(node:6588) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
(Use node --trace-deprecation ...
to show where the warning was created)
⨯ Failed to start server
Error: listen UNKNOWN: unknown error 0.0.0.0:3000
at Server.setupListenHandle [as _listen2] (node:net:1817:16)
at listenInCluster (node:net:1865:12)
at doListen (node:net:2014:7)
at process.processTicksAndRejections (node:internal/process/task_queues:83:21) {
code: 'UNKNOWN',
errno: -1,
syscall: 'listen',
address: '0.0.0.0',
port: 3000
}
Upvotes: 0
Views: 149
Reputation: 1585
I created Sample Nextjs Standalone app and deployed to Azure web app service windows.
In next.config file I have set the output to standalone.
next.config.mjs:
const nextConfig = {
output: 'standalone',
}
export default nextConfig;
For deploying nextjs app to Azure Web App Windows I added web.config and server.js files to root directory of the project.
To avoid the error use below server.js file.
server.js:
const { createServer } = require("http");
const next = require("next");
const port = process.env.PORT || 3000;
const dev = process.env.NODE_ENV !== "production";
const app = next({ dev });
const handle = app.getRequestHandler();
app.prepare().then(() => {
createServer((req, res) => {
handle(req, res);
}).listen(port, (err) => {
if (err) throw err;
console.log(`> Ready on http://localhost:${port}`);
});
});
web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
WebSocket support -->
<webSocket enabled="false" />
<handlers>
<add name="iisnode" path="server.js" verb="*" modules="iisnode"/>
</handlers>
<rewrite>
<rules>
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^server.js\/debug[\/]?" />
</rule>
<rule name="StaticContent">
<action type="Rewrite" url="public{REQUEST_URI}"/>
</rule>
<rule name="DynamicContent">
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
</conditions>
<action type="Rewrite" url="server.js"/>
</rule>
</rules>
</rewrite>
<security>
<requestFiltering>
<hiddenSegments>
<remove segment="bin"/>
</hiddenSegments>
</requestFiltering>
</security>
<httpErrors existingResponse="PassThrough" />
<iisnode watchedFiles="web.config;*.js"/>
</system.webServer>
</configuration>
I deployed nextjs app to Azure App service through VS code.
Azure Web App Output:
Upvotes: 0