fix: improve support for running agentapi under a subpath#40
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR improves support for running agentapi under a subpath by fixing URL handling when the application doesn't own its subdomain. The changes ensure proper redirection and API URL construction when the chat interface is served from a non-root path.
Key changes:
- Updates the default agent API URL calculation in the chat client to use relative path navigation instead of assuming root domain ownership
- Modifies the server redirect logic to respect the configured chat base path
- Adds comprehensive test coverage for the redirect functionality
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
chat/src/components/chat-provider.tsx |
Updates default agent API URL to use relative path navigation ("../../") instead of window.location.origin |
lib/httpapi/server.go |
Refactors server to store chatBasePath as instance variable and use it in redirect logic; adds Handler() method for testing |
lib/httpapi/server_test.go |
Adds comprehensive test coverage for redirect functionality with different base path configurations |
ThomasK33
approved these changes
Jul 31, 2025
hugodutka
requested changes
Jul 31, 2025
| // `window.location.origin` but this assumes that the application owns the | ||
| // entire origin. | ||
| // See: https://github.com/coder/coder/issues/18779#issuecomment-3133290494 for more context. | ||
| const defaultAgentAPIURL = new URL("../../", window.location.href).toString(); |
Collaborator
There was a problem hiding this comment.
I'm afraid this won't always work. Chat is hosted both at /chat and /chat/embed - the /chat/embed route has a simplified UI.
I created #42 to suggest a workaround.
Co-authored-by: Cian Johnston <cian@coder.com>
hugodutka
approved these changes
Jul 31, 2025
hugodutka
approved these changes
Jul 31, 2025
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Relates to coder/coder#18779
Previously, we had been defaulting
agentAPIURLtowindow.location.originwhich assumes the application owns its subdomain. This is not necessarily the case ifagentapiis running under a subpath.A 'good enough' fix seems to be defaulting to "two levels up" from
/chat/embed.Additionally, when redirecting to
/chat/embedfrom/, we also need to takechatBasePathinto account.