瀏覽代碼

fix: include pathname in pubsub URL

Fela Maslen 5 年之前
父節點
當前提交
0560b448f9
共有 2 個文件被更改,包括 6 次插入5 次删除
  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 {