feat: remove agent name from app URLs (#19750)

## Summary

In this pull request we're removing `agent_name` from subdomains in APP
urls when an `app` is used in the subdomain. `agent_names` will still be
used when a `port` is used in the subdomain.

Closes: https://github.com/coder/coder/issues/18485

### Changes

- Updated regex to support an optional agent name
- Added logic to support checking the app slug for a matching port
(e.g., 8080 or 8080s)

### Testing

- Updated all tests to support an optional `agent_name`
This commit is contained in:
Rafael Rodriguez
2025-09-26 12:25:58 -05:00
committed by GitHub
parent 403a9e57c9
commit d29a52462b
6 changed files with 359 additions and 99 deletions
+8 -1
View File
@@ -532,13 +532,20 @@ func AppSubdomain(dbApp database.WorkspaceApp, agentName, workspaceName, ownerNa
if appSlug == "" {
appSlug = dbApp.DisplayName
}
// Agent name is optional when app slug is present
normalizedAgentName := agentName
if !appurl.PortRegex.MatchString(appSlug) {
normalizedAgentName = ""
}
return appurl.ApplicationURL{
// We never generate URLs with a prefix. We only allow prefixes when
// parsing URLs from the hostname. Users that want this feature can
// write out their own URLs.
Prefix: "",
AppSlugOrPort: appSlug,
AgentName: agentName,
AgentName: normalizedAgentName,
WorkspaceName: workspaceName,
Username: ownerName,
}.String()