Quellcode durchsuchen

fix: include pathname in pubsub URL

Fela Maslen vor 5 Jahren
Ursprung
Commit
0560b448f9
2 geänderte Dateien mit 6 neuen und 5 gelöschten Zeilen
  1. 5 4
      gmus-web/src/utils/url.spec.ts
  2. 1 1
      gmus-web/src/utils/url.ts

+ 5 - 4
gmus-web/src/utils/url.spec.ts

@@ -7,10 +7,11 @@ describe(getPubsubUrl.name, () => {
   });
 
   describe.each`
-    case                 | apiUrl                     | testCase          | expectedPubsubUrl
-    ${'is https'}        | ${'https://some.api:1876'} | ${'a secure URL'} | ${'wss://some.api:1876/pubsub'}
-    ${'has no port'}     | ${'http://some.api'}       | ${'no port'}      | ${'ws://some.api/pubsub'}
-    ${'has no protocol'} | ${'//some.api'}            | ${'no protocol'}  | ${'ws://some.api/pubsub'}
+    case                 | apiUrl                     | testCase                 | expectedPubsubUrl
+    ${'is https'}        | ${'https://some.api:1876'} | ${'a secure URL'}        | ${'wss://some.api:1876/pubsub'}
+    ${'has no port'}     | ${'http://some.api'}       | ${'no port'}             | ${'ws://some.api/pubsub'}
+    ${'has no protocol'} | ${'//some.api'}            | ${'the origin protocol'} | ${'ws://some.api/pubsub'}
+    ${'has a path'}      | ${'http://some/api'}       | ${'the full URL'}        | ${'ws://some/api/pubsub'}
   `('when the URL $case', ({ testCase, apiUrl, expectedPubsubUrl }) => {
     const envBefore = process.env.REACT_APP_API_URL;
     beforeAll(() => {

+ 1 - 1
gmus-web/src/utils/url.ts

@@ -10,7 +10,7 @@ export function getPubsubUrl(): string {
   const apiUrl = new URL(getApiUrl());
   return `${apiUrl.protocol === 'https:' ? 'wss' : 'ws'}://${apiUrl.hostname}${
     apiUrl.port ? `:${apiUrl.port}` : ''
-  }/pubsub`;
+  }${apiUrl.pathname}${apiUrl.pathname === '/' ? '' : '/'}pubsub`;
 }
 
 export function getSongUrl(songId: number): string {