-
Notifications
You must be signed in to change notification settings - Fork 62
fix: improve support for running agentapi under a subpath #40
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
// `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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oof, TIL
Co-authored-by: Cian Johnston <cian@coder.com>
Relates to coder/coder#18779
Previously, we had been defaulting
agentAPIURL
towindow.location.origin
which assumes the application owns its subdomain. This is not necessarily the case ifagentapi
is running under a subpath.A 'good enough' fix seems to be defaulting to "two levels up" from
/chat/embed
.Additionally, when redirecting to
/chat/embed
from/
, we also need to takechatBasePath
into account.