origin.ts 805 B

1234567891011121314151617181920
  1. export default function getOrigin(suffix: string = '', type: string = 'http') {
  2. if (type === 'ws') {
  3. if (import.meta.env.VITE_SERVER_PROTOCOL === 'https:') {
  4. return `wss://${import.meta.env.VITE_SERVER_HOSTNAME}${suffix}`
  5. } else if (!import.meta.env.VITE_SERVER_PROTOCOL) {
  6. if (window.location.protocol === 'https:') {
  7. return `wss://${window.location.hostname}${suffix}`
  8. } else {
  9. return `ws://${window.location.hostname}${suffix}`
  10. }
  11. }
  12. return `ws://${import.meta.env.VITE_SERVER_HOSTNAME}${suffix}`
  13. }
  14. if (import.meta.env.VITE_SERVER_HOSTNAME) {
  15. return `${import.meta.env.VITE_SERVER_PROTOCOL}//${import.meta.env.VITE_SERVER_HOSTNAME}${suffix}`
  16. } else {
  17. return `${window.location.protocol}//${window.location.hostname}${suffix}`
  18. }
  19. }