nitro
nitro copied to clipboard
Unable to pick a custom port for dev mode, yet code exists to do so
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
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)
Have you tried setting the PORT environment variable?
Yep, with no luck We even tried adding it to doppler (our secrets manager that injects into the env)
![Code-RWP30DAS](https://user-images.githubusercontent.com/44125644/174952718-cb1a6cd4-f8c0-4090-a55f-da7e074a5076.png)
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.
Looking at the commit history for src/cli/commands/dev.ts
:
- After v2.3.1, port couldn't be specified when using the
nitropack dev
command since the port options weren't passed to the listen call. - v2.6.0, fixes support for using
PORT
. See commit.NITRO_PORT
is still unsupported for CLI dev.