Closed Deraen closed 8 years ago
Passing an option of --port 0
will actually select the first available local port both for jetty
and httpkit
.
The only problem with that approach is that the info message is not reporting the correct port and other tasks have no way of determining the used port number either. So something like :localport
has to be added as metadata to the fileset
.
I will have a deeper look at the code and try to come up with a PR for that.
httpkit returns the port as a key in run-server
s return value:
https://github.com/http-kit/http-kit/blob/master/src/org/httpkit/server.clj#L8
I guess Jetty has similar functionality. Maybe that could be used to print the correct port.
--port 0
meaning "random" is a bit unintuitive but I guess that could be solved with the docstring.
The --port 0
option is the idiomatic Java way of doing it. Jetty
and httpkit
both work this way already, so there is nothing to be changed here. It will only be passed on. My point was really that the resulting port should be reported correctly and made accessible to other tasks.
Jetty
provides a (.getPort server)
and httpkit
adds meta-data to the stop-server
function as you have already pointed out. So it should not be too hard. ;-)
I guess, this can be closed now as https://github.com/pandeiro/boot-http/pull/37 and https://github.com/pandeiro/boot-http/pull/38 have been merged successfully.
:+1: thanks everyone
I often have multiple projects open and Boot running for multiple projects. Often the projects are configured to use the same ports but in case of development server the specific port rarely matters. Would be useful if a free port was selected.
Could be a option to enable this, if we want to keep the current behavior.