File tree Expand file tree Collapse file tree 3 files changed +239
-58
lines changed Expand file tree Collapse file tree 3 files changed +239
-58
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,22 @@ class HttpRequests {
1717 }
1818 this . url = config . host
1919 }
20+ static constructCorrectPath ( pathname : string , url : string ) : string {
21+ let slash = '/'
22+ if ( pathname . endsWith ( '/' ) || url . startsWith ( '/' ) ) {
23+ slash = ''
24+ }
25+ if ( pathname . endsWith ( '//' ) ) {
26+ pathname = pathname . substring ( 1 )
27+ }
28+ if ( url . endsWith ( '/' ) ) {
29+ url = url . slice ( 0 , - 1 )
30+ }
31+ if ( pathname . endsWith ( '/' ) && url . startsWith ( '/' ) ) {
32+ url = url . substring ( 1 )
33+ }
34+ return pathname + slash + url
35+ }
2036
2137 async request ( {
2238 method,
@@ -33,16 +49,17 @@ class HttpRequests {
3349 } ) {
3450 try {
3551 const constructURL = new URL ( this . url )
36- constructURL . pathname = constructURL . pathname + url
37-
52+ constructURL . pathname = HttpRequests . constructCorrectPath (
53+ constructURL . pathname ,
54+ url
55+ )
3856 if ( params ) {
3957 const queryParams = new URLSearchParams ( )
4058 Object . keys ( params )
4159 . filter ( ( x : string ) => params [ x ] !== null )
4260 . map ( ( x : string ) => queryParams . set ( x , params [ x ] ) )
4361 constructURL . search = queryParams . toString ( )
4462 }
45-
4663 const response : Response = await fetch ( constructURL . toString ( ) , {
4764 ...config ,
4865 method,
You can’t perform that action at this time.
0 commit comments