Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem iisnode with Next release higher than 13.4.12 #137

Open
VittorioMorellini opened this issue Oct 18, 2023 · 2 comments
Open

Problem iisnode with Next release higher than 13.4.12 #137

VittorioMorellini opened this issue Oct 18, 2023 · 2 comments

Comments

@VittorioMorellini
Copy link

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
Copy link

Were you able to fix this?

@lextm
Copy link

lextm commented Jun 1, 2024

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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants