Azure / iisnode

Hosting node.js applications in IIS on Windows
Other
667 stars 101 forks source link

Problem iisnode with Next release higher than 13.4.12 #137

Open VittorioMorellini opened 1 year ago

VittorioMorellini commented 1 year ago

I have a Next application, it is deployed on IIS7. I am using pages directory and node for the api to get sql Server Data.

Till the release 13.4.12 it works fine. After that release it does not work, everything is bad. Css and images are not loaded and also the dynamic search is not correct, there is always 404 error

Can you suggest some solution? what can I do? I use the last versione of IISnode 0.2.21 and a Server.js file that is launched by iis with the iisnode handler:

process.env.NODE_ENV = 'production' process.chdir(__dirname)

const NextServer = require('next/dist/server/next-server').default const http = require('http') const path = require('path') const url = require('url') const nextConfig = require('./next.config.json')

// Make sure commands gracefully respect termination signals (e.g. from Docker) process.on('SIGTERM', () => process.exit(0)) process.on('SIGINT', () => process.exit(0))

const getPort = (defaultPort) => { const envPort = process.env.PORT

if (typeof envPort === 'undefined') { return defaultPort }

const parsedPort = parseInt(envPort, 10) return Number.isNaN(parsedPort) ? envPort : parsedPort }

const getEnv = (defaultEnv) => { const env = process.env.APP_ENV || process.env.NODE_ENV

if (typeof env !== 'undefined') { return env }

return defaultEnv }

let nextRequestHandler

const server = http.createServer(async (req, res) => { const parsedUrl = url.parse(req.url, true)

try { await nextRequestHandler(req, res, parsedUrl) } catch (err) { // eslint-disable-next-line no-console console.error(err)

res.statusCode = 500
res.end('internal server error')

} })

const serverEnv = getEnv('production')

const serverConfig = { hostname: '0.0.0.0', port: getPort(3000), dir: path.join(__dirname), dev: serverEnv === 'development', conf: nextConfig }

server.listen(serverConfig.port, serverConfig.hostname, (err) => { if (err) { // eslint-disable-next-line no-console console.error('Failed to start server', err)

process.exit(1)

}

const nextServer = new NextServer(serverConfig)

nextRequestHandler = nextServer.getRequestHandler()

// eslint-disable-next-line no-console console.log( > Server listening at http://${serverConfig.hostname}:${serverConfig.port} as ${serverEnv} env ) })

Is there anybody that can help me? Do you need some more config files?

TheBinaryGuy commented 10 months ago

Were you able to fix this?

lextm commented 5 months ago

This project hasn't got enough maintenance for years, so like you might find from other issues things are falling apart.

But you might try to use HttpPlatformHandler to host Next.js web apps on IIS, https://docs.lextudio.com/blog/running-next-js-web-apps-on-iis-with-httpplatformhandler/