]> Untitled Git - lemmy-ui.git/blob - src/shared/env.ts
Merge remote-tracking branch 'origin/drone-ci' into drone-ci-dess
[lemmy-ui.git] / src / shared / env.ts
1 import { isBrowser } from './utils';
2
3 const testHost = 'localhost:8536';
4
5 const internalHost =
6   (!isBrowser() && process.env.LEMMY_INTERNAL_HOST) || testHost; // used for local dev
7 export const externalHost = isBrowser()
8   ? `${window.location.hostname}${
9       ['1234', '1235'].includes(window.location.port)
10         ? ':8536'
11         : window.location.port == ''
12         ? ''
13         : `:${window.location.port}`
14     }`
15   : process.env.LEMMY_EXTERNAL_HOST || testHost;
16
17 const secure = isBrowser()
18   ? window.location.protocol == 'https:'
19     ? 's'
20     : ''
21   : process.env.LEMMY_HTTPS == 'true'
22   ? 's'
23   : '';
24
25 const host = isBrowser() ? externalHost : internalHost;
26
27 const httpBase = `http://${host}`; // Don't use secure here
28 export const wsUri = `ws${secure}://${host}/api/v2/ws`;
29 export const httpUri = `${httpBase}/api/v2`;
30 export const pictrsUri = `http${secure}://${host}/pictrs/image`;
31
32 console.log(`httpbase: ${httpBase}`);
33 console.log(`wsUri: ${wsUri}`);
34
35 // This is for html tags, don't include port
36 const httpExternalUri = `http${secure}://${externalHost.split(':')[0]}`;
37 export function httpExternalPath(path: string) {
38   return `${httpExternalUri}${path}`;
39 }