Skip to content

feat: support wildcard apps over tunnel #4602

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

Merged
merged 1 commit into from
Oct 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions cli/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,25 @@ func Server(dflags *codersdk.DeploymentFlags, newAPI func(context.Context, *code
)
defer closeTunnel()

// If the access URL is empty, we attempt to run a reverse-proxy tunnel
// to make the initial setup really simple.
// If the access URL is empty, we attempt to run a reverse-proxy
// tunnel to make the initial setup really simple.
if dflags.AccessURL.Value == "" {
cmd.Printf("Opening tunnel so workspaces can connect to your deployment. For production scenarios, specify an external access URL\n")
tunnel, tunnelErr, err = devtunnel.New(ctxTunnel, logger.Named("devtunnel"))
if err != nil {
return xerrors.Errorf("create tunnel: %w", err)
}
dflags.AccessURL.Value = tunnel.URL

if dflags.WildcardAccessURL.Value == "" {
u, err := parseURL(ctx, tunnel.URL)
if err != nil {
return xerrors.Errorf("parse tunnel url: %w", err)
}

// Suffixed wildcard access URL.
dflags.WildcardAccessURL.Value = fmt.Sprintf("*--%s", u.Hostname())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this just be one hypen?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

acutaly looks like ti deosnt matter

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah it doesn't matter on the server side how many hyphens you use, but I used two here so it matches the two hyphens between each app component

}
}

accessURLParsed, err := parseURL(ctx, dflags.AccessURL.Value)
Expand Down Expand Up @@ -735,7 +745,7 @@ func Server(dflags *codersdk.DeploymentFlags, newAPI func(context.Context, *code

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

return func() { _ = srv.Close() }
return func() {
_ = srv.Close()
}
}

// embeddedPostgresURL returns the URL for the embedded PostgreSQL deployment.
Expand Down