]> Untitled Git - lemmy-ui.git/blob - src/shared/env.ts
Adding https flag. Fixes #7
[lemmy-ui.git] / src / shared / env.ts
1 import { isBrowser } from './utils';
2
3 const testHost = 'localhost:8536';
4
5 const internalHost = process.env.LEMMY_INTERNAL_HOST || testHost; // used for local dev
6 export const externalHost = isBrowser()
7   ? `${window.location.hostname}:${
8       window.location.port == '1234' || window.location.port == '1235'
9         ? 8536
10         : window.location.port
11     }`
12   : process.env.LEMMY_EXTERNAL_HOST || testHost;
13
14 const secure = isBrowser()
15   ? window.location.protocol == 'https:'
16     ? 's'
17     : ''
18   : process.env.LEMMY_HTTPS == 'true'
19   ? 's'
20   : '';
21
22 const host = isBrowser() ? externalHost : internalHost;
23
24 const httpBase = `http${secure}://${host}`;
25 export const wsUri = `ws${secure}://${host}/api/v1/ws`;
26 export const httpUri = `${httpBase}/api/v1`;
27 export const pictrsUri = `${httpBase}/pictrs/image`;
28
29 // This is for html tags, don't include port
30 const httpExternalUri = `http${secure}://${externalHost.split(':')[0]}`;
31 export function httpExternalPath(path: string) {
32   return `${httpExternalUri}${path}`;
33 }