Cli: Support non-random port assignment?

Created on 7 May 2019  ยท  12Comments  ยท  Source: netlify/cli

Is it possible to run netlify dev and specify which port the dev server will listen on?

At the moment it seems to select a random open port which makes it difficult to integrate with existing development processes.

The --port argument and config currently relate to the application port that will be proxied by netlify dev, but it looks like there is no way to configure netlify dev's port.

dev

All 12 comments

hi! I dont think this is possible right now but this is important feedback. believe it or not, i think we used to have this, but actually removed this because we didnt think we'd need it.

meanwhile, feel free to add your own detector like this and the field you want is called port in there (confusingly, proxyPort is for other stuff). this is a hack, if you rather wait for an official solution i can't promise an ETA for you since we need to have an overall design convo about this and related config.

cc @biilmann

Thank you for the insight @sw-yx.

Can I point out that netlify-dev-server itself requires awareness/detection of common/configurable ports for the local services that it proxies but itself does not provide a configurable or memorable port to the downstream user. This hampers the developer experience.

As an illustration, here's the terminal output when I spin up my dev server, the output from my app means that I need to scroll back up and hunt for the randomised port so I can open the web browser.

yarn run v1.15.2
$ netlify dev
โ—ˆ Netlify Dev โ—ˆ
โ—ˆ Injected build setting env var:  <snipped>
โ—ˆ Injected build setting env var:  <snipped>
โ—ˆ Injected build setting env var:  <snipped>
โ—ˆ Injected build setting env var:  <snipped>
โ—ˆ Injected build setting env var:  <snipped>
โ—ˆ Injected build setting env var:  <snipped>
โ—ˆ Injected build setting env var:  <snipped>
โ—ˆ Overriding urlRegexp with setting derived from netlify.toml [dev] block:  /(http:\/\/)([^:]+:)4001(\/)?/g
โ—ˆ Starting Netlify Dev with undefined
Waiting for localhost:4001.
โ—ˆ Lambda server is listening on 34567
$ poi src/index.js --port 4001
..> Running in development mode
> Using external Poi config file
> location: "~/Sites/<snipped>/poi.config.js"
> Bundling with Webpack 3.12.0
.
Connected!
Waiting for localhost:34567.
Connected!

   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
   โ”‚                                                  โ”‚
   โ”‚   โ—ˆ Server now ready on http://localhost:64316   โ”‚
   โ”‚                                                  โ”‚
   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                            Asset       Size  Chunks                    Chunk Names
<snipped 79 lines>
                                 client.worker.js    1.52 MB          [emitted]  [big]
                                       index.html  593 bytes          [emitted]

> Open http://localhost:4001 (copied!)
> On Your Network: http://192.168.1.108:4001

 DONE  Build 5d430e finished in 9900 ms!

Thanks for considering the issue!

i understand and sympathize. its not something i wanna decide alone because we'll want to do this and possibly some other breaking changes to our config all at once so as to minimize confusion. you are 100% welcome to fork this plugin (instructions) in the meantime while we hire to build out this team and have the design discussions we need to have.

@sw-yx all good, thank you. I'll keep an eye on the issue and see if a fork would be simple enough.

@sw-yx this is a _massive_ problem in monorepos.

I have twelve packages all using netlify dev and the ports change between every reboot and disappear into the barrage of console output.

We need to be able to specify the port.

If anything, make it backwards compatible, so that:

port sets the port to proxy by default.

if proxyPort is provided, port sets the port netlify dev's proxy serves from.

I would be _happy_ to do this work, just point me in the right direction.

cc @biilmann

I have twelve packages all using netlify dev and the ports change between every reboot and disappear into the barrage of console output.

i'm not exactly sure how you are using netlify dev in a monorepo. are you running 12 instances of netlify dev? i cant imagine why you'd do that regularly?

in any case, if you're not using some sort of supported static site generator/project (which it sounds like you arent), then you're getting the "simple static server" and the relevant code is https://github.com/netlify/netlify-dev-plugin/blob/master/src/commands/dev/index.js#L212-L217

You only get that "simple static server" block of settings if you aren't setting command in netlify.toml under [dev], which leaves the port setting undefined and therefore get-port always returns a dynamic port. It seems to me that 8888 is the generally accepted default port to be hosting the whole dev stack on, so I think most people would be happy if you used that as a default here if no other port was set at that point:
https://github.com/netlify/netlify-dev-plugin/blob/master/src/commands/dev/index.js#L100

This is separate from being able to configure what that dev server port should be.

indeed it is less than a oneliner. putting it in.

thanks for everyone's patience while we hire a fulltime cli dev to address all these issues.

@colinbate [email protected]

@sw-yx this still seems to be a lovely mess.

as far as I can tell, none of the port configs even work or do anything.

I wanted to change which port the "Server now ready on ..." uses.

Neither --port flag or lines in the netlify.toml [dev] block have seemingly any effect.

Frustrating.

Great! Thank you, @RaeesBhatti ๐ŸŽ‰

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cco3 picture cco3  ยท  4Comments

karl-cardenas-coding picture karl-cardenas-coding  ยท  4Comments

iamskok picture iamskok  ยท  3Comments

lukasluecke picture lukasluecke  ยท  3Comments

bendg25 picture bendg25  ยท  5Comments