nitro icon indicating copy to clipboard operation
nitro copied to clipboard

Unable to pick a custom port for dev mode, yet code exists to do so

Open sasial-dev opened this issue 2 years ago • 6 comments

Environment

Nitropack: 0.4.8 Node: 16.11.0

Reproduction

N/A

Describe the bug

As shown at https://github.com/unjs/nitro/blob/main/src/cli.ts#L22 - there is the code avaliable to allow users to pick a custom port/configure the dev server further.

Additional context

We need to pick a port to allow use to debug our serverside while using our frontend on port :3000. We have a specific port we need to pin it on, but we can't.

Logs

No response

sasial-dev avatar Jun 22 '22 01:06 sasial-dev

As a workaround, we've liturally got a .js script with:

import { createDevServer, createNitro, build, prepare } from 'nitropack'

const nitro = await createNitro({
    dev: true,
    preset: 'nitro-dev'
})
const server = createDevServer(nitro)
await server.listen(50451)
await prepare(nitro)
await build(nitro)

sasial-dev avatar Jun 22 '22 01:06 sasial-dev

Have you tried setting the PORT environment variable?

danielroe avatar Jun 22 '22 05:06 danielroe

Yep, with no luck We even tried adding it to doppler (our secrets manager that injects into the env)

sasial-dev avatar Jun 22 '22 05:06 sasial-dev

Code-RWP30DAS

sasial-dev avatar Jun 22 '22 05:06 sasial-dev

Any news on this @danielroe ? NITRO_PORT doesn't work for me in dev, but PORT does work. PORT is already used for many other things and we want to keep dev analogue to prod, where we use NITRO_PORT. With different env variables, it's difficult to create a consistent dev experience, especially as there are no cli parameters to specify the port.

itpropro avatar Oct 15 '22 12:10 itpropro

Looking at the commit history for src/cli/commands/dev.ts:

michaelkplai avatar Feb 11 '24 20:02 michaelkplai