English 中文(简体)
无法获得Lextjs 14号申请, 无法在IIS的子应用下使用
原标题:Cannot get Nextjs 14 application serving under sub application in IIS
I have a basic Next 14 app that I am hosting under IIS website on the root that works fine. If I create a sub application off the root and move the application there, I get a 404 when browsing to root/subapplication. My Server.js file looks like this const { createServer } = require( http ) const { parse } = require( url ) const next = require( next ) const dev = process.env.NODE_ENV !== production const port = process.env.PORT || 3010; const app = next({ dev }) const handle = app.getRequestHandler() app.prepare().then(() => { createServer((req, res) => { // Be sure to pass `true` as the second argument to `url.parse`. // This tells it to parse the query portion of the URL. const parsedUrl = parse(req.url, true) const { pathname, query } = parsedUrl if (pathname === /a ) { app.render(req, res, /a , query) } else if (pathname === /b ) { app.render(req, res, /b , query) } else { handle(req, res, parsedUrl) } }).listen(port, (err) => { if (err) throw err console.log(`> Ready on http://localhost:${port}`) }) }) And the web.config looks like: I have tried following every article / post on this I can find and nothing is working. I have tried modifying my next.config.mjs to specify a supPath in various ways and none of those have worked. What do I need to do to?
问题回答
I was able to get this working following Lex Li s blog post https://docs.lextudio.com/blog/running-next-js-web-apps-on-iis-with-httpplatformhandler/ Initially I had assumed that I still required my rewrite rule that forwarded requests to my server.js, but that was not the case and taking the web.config up from that article in full and ditching iisnode entirely fixed the problem. Adding the basePath value additionally allowed for static files to be requested from the correct URL.




相关问题
How to make Sequelize use singular table names

I have an model called User but Sequelize looks for the table USERS whenever I am trying to save in the DB. Does anyone know how to set Sequelize to use singular table names? Thanks.

What is Node.js? [closed]

I don t fully get what Node.js is all about. Maybe it s because I am mainly a web based business application developer. What is it and what is the use of it? My understanding so far is that: The ...

Clientside going serverside with node.js

I`ve been looking for a serverside language for some time, and python got my attention somewhat. But as I already know and love javascript, I now want learn to code on the server with js and node.js. ...

Can I use jQuery with Node.js?

Is it possible to use jQuery selectors/DOM manipulation on the server-side using Node.js?

How do I escape a string for a shell command in node?

In nodejs, the only way to execute external commands is via sys.exec(cmd). I d like to call an external command and give it data via stdin. In nodejs there does yet not appear to be a way to open a ...

热门标签