Skip to content

Commit 47cb9ab

Browse files
authored
feat: support wildcard apps over tunnel (coder#4602)
1 parent 43d1f72 commit 47cb9ab

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

cli/server.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,15 +208,25 @@ func Server(dflags *codersdk.DeploymentFlags, newAPI func(context.Context, *code
208208
)
209209
defer closeTunnel()
210210

211-
// If the access URL is empty, we attempt to run a reverse-proxy tunnel
212-
// to make the initial setup really simple.
211+
// If the access URL is empty, we attempt to run a reverse-proxy
212+
// tunnel to make the initial setup really simple.
213213
if dflags.AccessURL.Value == "" {
214214
cmd.Printf("Opening tunnel so workspaces can connect to your deployment. For production scenarios, specify an external access URL\n")
215215
tunnel, tunnelErr, err = devtunnel.New(ctxTunnel, logger.Named("devtunnel"))
216216
if err != nil {
217217
return xerrors.Errorf("create tunnel: %w", err)
218218
}
219219
dflags.AccessURL.Value = tunnel.URL
220+
221+
if dflags.WildcardAccessURL.Value == "" {
222+
u, err := parseURL(ctx, tunnel.URL)
223+
if err != nil {
224+
return xerrors.Errorf("parse tunnel url: %w", err)
225+
}
226+
227+
// Suffixed wildcard access URL.
228+
dflags.WildcardAccessURL.Value = fmt.Sprintf("*--%s", u.Hostname())
229+
}
220230
}
221231

222232
accessURLParsed, err := parseURL(ctx, dflags.AccessURL.Value)
@@ -752,7 +762,7 @@ func Server(dflags *codersdk.DeploymentFlags, newAPI func(context.Context, *code
752762

753763
// parseURL parses a string into a URL. It works around some technically correct
754764
// but undesired behavior of url.Parse by prepending a scheme if one does not
755-
// exist so that the URL does not get parsed improprely.
765+
// exist so that the URL does not get parsed improperly.
756766
func parseURL(ctx context.Context, u string) (*url.URL, error) {
757767
var (
758768
hasScheme = strings.HasPrefix(u, "http:") || strings.HasPrefix(u, "https:")
@@ -1108,7 +1118,9 @@ func serveHandler(ctx context.Context, logger slog.Logger, handler http.Handler,
11081118
}
11091119
}()
11101120

1111-
return func() { _ = srv.Close() }
1121+
return func() {
1122+
_ = srv.Close()
1123+
}
11121124
}
11131125

11141126
// embeddedPostgresURL returns the URL for the embedded PostgreSQL deployment.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy