url.ts 566 B

123456789101112131415161718
  1. export function getApiUrl(): string {
  2. const baseUrl = process.env.REACT_APP_API_URL ?? 'http://localhost:3000';
  3. if (baseUrl.startsWith('//')) {
  4. return `${window.location.protocol}${baseUrl}`;
  5. }
  6. return baseUrl;
  7. }
  8. export function getPubsubUrl(): string {
  9. const apiUrl = new URL(getApiUrl());
  10. return `${apiUrl.protocol === 'https:' ? 'wss' : 'ws'}://${apiUrl.hostname}${
  11. apiUrl.port ? `:${apiUrl.port}` : ''
  12. }/pubsub`;
  13. }
  14. export function getSongUrl(songId: number): string {
  15. return `${process.env.REACT_APP_API_URL}/stream?songid=${songId}`;
  16. }