support port=0 for os-decide

Massimo Melina committed Jan 21, 2022 at 15:07 UTC 8e5b37466bc9d87079a3f57addd4ffa8970aa46b
3 files changed +11 -3
config.yaml
+2 -2
@@ -1,5 +1,5 @@
1 -# BEWARE all lines starting with # are disabled, just placeholders. If you need to set the option remove the initial #
2 -#port: 80
1 +# BEWARE all lines starting with # are ignored, just placeholders. Default values are used for such lines. If you need to set the option then remove the initial #
2 +port: 80 # 0 is a special value that will let the system pick a random available port. Use -1 to disable http, if you want https-only for example.
3 #max_kbps: 1000
4 #max_kbps_per_ip: 500
5 #log:
src/listen.ts
+8 -1
@@ -62,7 +62,14 @@ function startServer(srv: http.Server, port: number, secure:string='') {
62 return resolve(null)
63 srv.listen(port, () => {
64 const proto = 'http' + secure
65 - console.log(proto + ` serving on port`, port)
65 + const ad = srv.address()
66 + if (!ad)
67 + return reject('no address')
68 + if (typeof ad === 'string')
69 + return reject('type of socket not supported')
70 + port = ad.port
71 + console.log(proto, `serving on port`, port)
72 +
73 if (firstTime && getConfig('open_browser_at_start') !== false) {
74 open(proto + '://localhost:' + port).then()
75 firstTime = false
todo.md
+1
@@ -1,4 +1,5 @@
1 # To do
2 +- bigger checkbox (usability)
3 - filter: add button to invert selection
4 - filter: add button to select all
5 - log filter option