File tree Expand file tree Collapse file tree 1 file changed +10
-5
lines changed
Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -73,12 +73,17 @@ const useAgentAPIUrl = (): string => {
7373 // `window.location.origin` but this assumes that the application owns the
7474 // entire origin.
7575 // See: https://github.com/coder/coder/issues/18779#issuecomment-3133290494 for more context.
76- const chatUrl = new URL ( basePath , window . location . origin ) ;
77- const agentAPIUrl = new URL ( "../" , chatUrl . toString ( ) ) . toString ( ) ;
78- if ( agentAPIUrl . endsWith ( "/" ) ) {
79- return agentAPIUrl . slice ( 0 , - 1 ) ;
76+ let chatURL : string = new URL ( basePath , window . location . origin ) . toString ( ) ;
77+ // NOTE: trailing slashes and relative URLs are tricky.
78+ // https://developer.mozilla.org/en-US/docs/Web/API/URL_API/Resolving_relative_references#current_directory_relative
79+ if ( ! chatURL . endsWith ( "/" ) ) {
80+ chatURL += "/" ;
8081 }
81- return agentAPIUrl ;
82+ const agentAPIURL = new URL ( ".." , chatURL ) . toString ( ) ;
83+ if ( agentAPIURL . endsWith ( "/" ) ) {
84+ return agentAPIURL . slice ( 0 , - 1 ) ;
85+ }
86+ return agentAPIURL ;
8287} ;
8388
8489export function ChatProvider ( { children } : PropsWithChildren ) {
You can’t perform that action at this time.
0 commit comments