nitro icon indicating copy to clipboard operation
nitro copied to clipboard

Nuxt 3.7.0 with Nitro 2.6.2 build server cause port problem when deploy on azure app service

Open annndddy opened this issue 2 years ago • 15 comments

Environment

  • Operating System: Windows_NT
  • Node Version: v18.17.1
  • Nuxt Version: 3.7.0
  • CLI Version: 3.7.2
  • Nitro Version: 2.6.2
  • Package Manager: [email protected]

Reproduction

using a Nuxt 3.7.0 with Nitro 2.6.2 project yarn run build and deploy to a azure app service

Describe the bug

RangeError [ERR_SOCKET_BAD_PORT]: options.port should be >= 0 and < 65536. Received \.\pipe\a52b3a22-a8b8-516c-b23f-b824dbfe0c8f.at new NodeError (node:internal/errors:393:5)at validatePort (node:internal/validators:372:11)at Server.listen (node:net:1613:5)at file:///C:/home/site/wwwroot/.output/server/chunks/nitro/node-server.mjs:5617:25at ModuleJob.run (node:internal/modules/esm/module_job:193:25)at async Promise.all (index 0)at async ESMLoader.import (node:internal/modules/esm/loader:530:24)at async importModuleDynamicallyWrapper (node:internal/vm/module:438:15)

Additional context

currently edit .output/server/server/chunks/nitro/node-server.mjs const listener = server.listen(path ? { path } : { port, host }, (err) => { to const listener = server.listen(port, host, (err) => { can fix the problem

Logs

No response

annndddy avatar Aug 28 '23 08:08 annndddy

Can you please provide a reproduction? 🙏🏼

pi0 avatar Aug 28 '23 09:08 pi0

create a new project using npx nuxi@latest init nuxt3.7.0 https://github.com/annndddy/nuxt3.7.0

yarn run build and deploy the .output server.js web.config to the azure app service use browser to access the page and the server log will show Application has thrown an uncaught exception and is terminated: RangeError [ERR_SOCKET_BAD_PORT]: options.port should be >= 0 and < 65536. Received \.\pipe\25ca48bd-25d5-5ac8-b052-66e4d31687f7. at new NodeError (node:internal/errors:393:5) at validatePort (node:internal/validators:372:11) at Server.listen (node:net:1613:5) at file:///C:/home/site/wwwroot/.output/server/chunks/nitro/node-server.mjs:5499:25 at ModuleJob.run (node:internal/modules/esm/module_job:193:25) at async Promise.all (index 0) at async ESMLoader.import (node:internal/modules/esm/loader:530:24) at async importModuleDynamicallyWrapper (node:internal/vm/module:438:15)

and this is a error that happened before https://github.com/nuxt/nuxt/issues/14958 https://github.com/unjs/nitro/issues/507

annndddy avatar Aug 28 '23 09:08 annndddy

@annndddy I am having the same problem on IIS server. Did you solve the problem?

@pi0 Did you solve the problem?

tolgahanbeyazoglu avatar Sep 08 '23 19:09 tolgahanbeyazoglu

@tolgahanbeyazoglu currently i edit .output/server/server/chunks/nitro/node-server.mjs before deploy to fix the problem

annndddy avatar Sep 11 '23 01:09 annndddy

@annndddy I will continue to change it for now, I hope nuxt offers a solution. thank you

tolgahanbeyazoglu avatar Sep 11 '23 05:09 tolgahanbeyazoglu

Having the same problem on mittwald server. Instead of ports they give you a socket. How do I use this in Nuxt?

fabianwohlfart avatar Sep 12 '23 13:09 fabianwohlfart

NITRO_UNIX_SOCKET=[path_of_socket] (.\pipe\25ca48bd-25d5-5ac8-b052-66e4d31687f7) solves the issue for me.

fabianwohlfart avatar Sep 12 '23 13:09 fabianwohlfart

@fabianwohlfart Did you find a solution? If you found it, how to use it?

tolgahanbeyazoglu avatar Sep 14 '23 05:09 tolgahanbeyazoglu

@fabianwohlfart Did you find a solution? If you found it, how to use it?

Yes. So basically you have to tell your Nuxt application that a socket is used instead of a port. You are doing this by explicitly setting the NITRO_UNIX_SOCKET env variable to the path of your socket.

@pi0 I was wondering if there is a documentation about all possible env variables in the Nuxt docs?

fabianwohlfart avatar Sep 14 '23 06:09 fabianwohlfart

@tolgahanbeyazoglu @fabianwohlfart i using @fabianwohlfart idea to use the NITRO_UNIX_SOCKET by create a nitro plugin to set the value and it works now

nitroPlugins/unixsocket.ts

export default defineNitroPlugin((nitroApp) => {
    process.env.NITRO_UNIX_SOCKET = process.env.PORT
})

nuxt.config.ts

export default defineNuxtConfig({
 nitro: {
    plugins: ['~/nitroPlugins/unixsocket.ts']
  },
..
})

annndddy avatar Sep 14 '23 18:09 annndddy

@annndddy Thank you, it is surprising that there is no explanation on nuxt !!

tolgahanbeyazoglu avatar Sep 15 '23 19:09 tolgahanbeyazoglu

https://github.com/unjs/nitro/pull/1783/files was merged for IIS, I believe a similar approach could be used for Azure ?

Hebilicious avatar Oct 09 '23 02:10 Hebilicious

@Hebilicious thank you I don't understand how to use it ?

tolgahanbeyazoglu avatar Oct 09 '23 06:10 tolgahanbeyazoglu

@Hebilicious thank you I don't understand how to use it ?

You'd need to use either the plugin workaround (recommended) or a custom driver.

Hebilicious avatar Oct 09 '23 11:10 Hebilicious

Hello Does anyone know why NITRO_PORT=3001 works in .env but NITRO_UNIX_SOCKET=/tmp/my-new-nitro.sock does not?

project Nuxt 3.11.2 with Nitro 2.9.6

I need to give each user a different socket, as I am using a code-server, with the "Running Multiple code-server Instances on Different Ports" approach

IgorKha avatar Jun 13 '24 19:06 IgorKha