@@ -226,6 +226,20 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
226
226
}
227
227
defer httpListener .Close ()
228
228
229
+ listenAddrStr := httpListener .Addr ().String ()
230
+ // For some reason if 0.0.0.0:x is provided as the http address,
231
+ // httpListener.Addr().String() likes to return it as an ipv6
232
+ // address (i.e. [::]:x). If the input ip is 0.0.0.0, try to
233
+ // coerce the output back to ipv4 to make it less confusing.
234
+ if strings .Contains (cfg .HTTPAddress .Value , "0.0.0.0" ) {
235
+ listenAddrStr = strings .ReplaceAll (listenAddrStr , "[::]" , "0.0.0.0" )
236
+ }
237
+
238
+ // We want to print out the address the user supplied, not the
239
+ // loopback device.
240
+ cmd .Println ("Started HTTP listener at" , (& url.URL {Scheme : "http" , Host : listenAddrStr }).String ())
241
+
242
+ // Set the http URL we want to use when connecting to ourselves.
229
243
tcpAddr , tcpAddrValid := httpListener .Addr ().(* net.TCPAddr )
230
244
if ! tcpAddrValid {
231
245
return xerrors .Errorf ("invalid TCP address type %T" , httpListener .Addr ())
@@ -237,7 +251,6 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
237
251
Scheme : "http" ,
238
252
Host : tcpAddr .String (),
239
253
}
240
- cmd .Println ("Started HTTP listener at " + httpURL .String ())
241
254
}
242
255
243
256
var (
@@ -269,6 +282,22 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
269
282
httpsListener = tls .NewListener (httpsListenerInner , tlsConfig )
270
283
defer httpsListener .Close ()
271
284
285
+ listenAddrStr := httpsListener .Addr ().String ()
286
+ // For some reason if 0.0.0.0:x is provided as the https
287
+ // address, httpsListener.Addr().String() likes to return it as
288
+ // an ipv6 address (i.e. [::]:x). If the input ip is 0.0.0.0,
289
+ // try to coerce the output back to ipv4 to make it less
290
+ // confusing.
291
+ if strings .Contains (cfg .HTTPAddress .Value , "0.0.0.0" ) {
292
+ listenAddrStr = strings .ReplaceAll (listenAddrStr , "[::]" , "0.0.0.0" )
293
+ }
294
+
295
+ // We want to print out the address the user supplied, not the
296
+ // loopback device.
297
+ cmd .Println ("Started TLS/HTTPS listener at" , (& url.URL {Scheme : "https" , Host : listenAddrStr }).String ())
298
+
299
+ // Set the https URL we want to use when connecting to
300
+ // ourselves.
272
301
tcpAddr , tcpAddrValid := httpsListener .Addr ().(* net.TCPAddr )
273
302
if ! tcpAddrValid {
274
303
return xerrors .Errorf ("invalid TCP address type %T" , httpsListener .Addr ())
@@ -280,7 +309,6 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
280
309
Scheme : "https" ,
281
310
Host : tcpAddr .String (),
282
311
}
283
- cmd .Println ("Started TLS/HTTPS listener at " + httpsURL .String ())
284
312
}
285
313
286
314
// Sanity check that at least one listener was started.
0 commit comments