@@ -155,7 +155,8 @@ async function opGetAllThreads(
155155 csrfToken : string ,
156156 projectId : string ,
157157) : Promise < Map < string , OverleafThread > > {
158- const res = await fetch ( `https://www.overleaf.com/project/${ projectId } /threads` , {
158+ const currentDomain = window . location . hostname ;
159+ const res = await fetch ( `https://${ currentDomain } /project/${ projectId } /threads` , {
159160 headers : {
160161 Accept : "application/json" ,
161162 "Content-Type" : "application/json" ,
@@ -192,7 +193,8 @@ export async function postCommentToThread(
192193 projectId : string ,
193194 headers : HeadersInit ,
194195) : Promise < void > {
195- const threadUrl = `https://www.overleaf.com/project/${ projectId } /thread/${ threadId } /messages` ;
196+ const currentDomain = window . location . hostname ;
197+ const threadUrl = `https://${ currentDomain } /project/${ projectId } /thread/${ threadId } /messages` ;
196198 // console.log("Posting comment to thread:", threadUrl, comment);
197199
198200 if ( ! comment || comment . length === 0 ) {
@@ -225,7 +227,8 @@ export async function wsConnect(
225227 // if (import.meta.env.DEV) {
226228 // throw new Error("Development mode is not supported for wsConnect");
227229 // }
228- const baseUrl = import . meta. env . DEV ? "http://localhost:3000" : "https://www.overleaf.com" ;
230+ const currentDomain = window . location . hostname ;
231+ const baseUrl = import . meta. env . DEV ? "http://localhost:3000" : "https://" + currentDomain ;
229232 const res = await fetch ( `${ baseUrl } /socket.io/1/?projectId=${ projectId } &t=${ Date . now ( ) } ` , {
230233 headers : {
231234 Accept : "application/json" ,
@@ -239,13 +242,13 @@ export async function wsConnect(
239242 throw new Error ( `HTTP error when connecting ws: ${ res . status } ` ) ;
240243 }
241244
242- const wsUrl = import . meta. env . DEV ? "ws://localhost:3000" : "wss://www.overleaf.com" ;
245+ const wsUrl = import . meta. env . DEV ? "ws://localhost:3000" : "wss://" + currentDomain ;
243246 const data = await res . text ( ) ;
244247 const sessionId = data . split ( ":" ) [ 0 ] ;
245-
248+
246249 // Set cookies for WebSocket connection
247- document . cookie = `overleaf_session2=${ overleafAuth . cookieOverleafSession2 } ; path=/; domain=${ import . meta. env . DEV ? "localhost" : "www.overleaf.com" } ` ;
248- document . cookie = `GCLB=${ overleafAuth . cookieGCLB } ; path=/; domain=${ import . meta. env . DEV ? "localhost" : "www.overleaf.com" } ` ;
250+ document . cookie = `overleaf_session2=${ overleafAuth . cookieOverleafSession2 } ; path=/; domain=${ import . meta. env . DEV ? "localhost" : currentDomain } ` ;
251+ document . cookie = `GCLB=${ overleafAuth . cookieGCLB } ; path=/; domain=${ import . meta. env . DEV ? "localhost" : currentDomain } ` ;
249252
250253 return new WebSocket ( `${ wsUrl } /socket.io/1/websocket/${ sessionId } ?projectId=${ projectId } ` ) ;
251254}
0 commit comments