-
Notifications
You must be signed in to change notification settings - Fork 82
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
Changes from 8 commits
227ef9b
ace9c6a
60b542f
9f6efb4
7de9a8b
b1a1904
07eee10
01d97da
1a5500f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,7 +57,18 @@ export function ChatProvider({ children }: PropsWithChildren) { | |
const [serverStatus, setServerStatus] = useState<ServerStatus>("unknown"); | ||
const eventSourceRef = useRef<EventSource | null>(null); | ||
const searchParams = useSearchParams(); | ||
const agentAPIUrl = searchParams.get("url") || window.location.origin; | ||
// NOTE(cian): We use '../../' here to construct the agent API URL relative | ||
// to the current window location. Let's say the app is hosted on a subpath | ||
// `/@admin/workspace.agent/apps/ccw/`. When you visit this URL you get | ||
// redirected to `/@admin/workspace.agent/apps/ccw/chat/embed`. This serves | ||
// this React application, but it needs to know where the agent API is hosted. | ||
// This will be at the root of where the application is mounted e.g. | ||
// `/@admin/workspace.agent/apps/ccw/`. Previously we used | ||
// `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(); | ||
|
||
const agentAPIUrl = searchParams.get("url") || defaultAgentAPIURL; | ||
|
||
// Set up SSE connection to the events endpoint | ||
useEffect(() => { | ||
|
Uh oh!
There was an error while loading. Please reload this page.