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

Support non-random port assignment? #173

Open
mattlenz opened this issue May 7, 2019 · 10 comments

Comments

Projects
None yet
4 participants
@mattlenz
Copy link

commented May 7, 2019

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.

@sw-yx

This comment has been minimized.

Copy link
Contributor

commented May 7, 2019

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

@mattlenz

This comment has been minimized.

Copy link
Author

commented May 7, 2019

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!

@sw-yx

This comment has been minimized.

Copy link
Contributor

commented May 7, 2019

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.

@mattlenz

This comment has been minimized.

Copy link
Author

commented May 7, 2019

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

@chrisdmacrae

This comment has been minimized.

Copy link

commented Jun 6, 2019

@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.

@chrisdmacrae

This comment has been minimized.

Copy link

commented Jun 6, 2019

@sw-yx

This comment has been minimized.

Copy link
Contributor

commented Jun 7, 2019

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

@colinbate

This comment has been minimized.

Copy link

commented Jun 17, 2019

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.

@sw-yx

This comment has been minimized.

Copy link
Contributor

commented Jun 17, 2019

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.

sw-yx pushed a commit that referenced this issue Jun 17, 2019

@sw-yx

This comment has been minimized.

Copy link
Contributor

commented Jun 17, 2019

@colinbate netlify-cli@2.11.23

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.