UNPKG

650 BPlain TextView Raw
1const CLIENT_BASE_URL =
2 typeof window !== 'undefined' && window.location
3 ? `${window.location.protocol}//${window.location.host}`
4 : ``
5
6export function getURL() {
7 // We should use `CLIENT_BASE_URL` on the client as we can't guarantee how the client is connected to the server - it's possible that the server is listening on `127.0.0.1` and the client is connected via `localhost`. Things might break if URLs don't match due to a JS module being double-loaded via two different URLs.
8 // `process.env.ONE_SERVER_URL` is for the server, where `CLIENT_BASE_URL` will be blank.
9 return CLIENT_BASE_URL || process.env.ONE_SERVER_URL || ''
10}