]> Untitled Git - lemmy-ui.git/blob - src/shared/env.ts
Merge pull request #59 from LemmyNet/pictrs_v2
[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       ['1234', '1235'].includes(window.location.port)
9         ? ':8536'
10         : window.location.port == ''
11         ? ''
12         : `:${window.location.port}`
13     }`
14   : process.env.LEMMY_EXTERNAL_HOST || testHost;
15
16 const secure = isBrowser()
17   ? window.location.protocol == 'https:'
18     ? 's'
19     : ''
20   : process.env.LEMMY_HTTPS == 'true'
21   ? 's'
22   : '';
23
24 const host = isBrowser() ? externalHost : internalHost;
25
26 const httpBase = `http://${host}`; // Don't use secure here
27 export const wsUri = `ws${secure}://${host}/api/v1/ws`;
28 export const httpUri = `${httpBase}/api/v1`;
29 export const pictrsUri = `http${secure}://${host}/pictrs/image`;
30
31 console.log(`httpbase: ${httpBase}`);
32 console.log(`wsUri: ${wsUri}`);
33
34 // This is for html tags, don't include port
35 const httpExternalUri = `http${secure}://${externalHost.split(':')[0]}`;
36 export function httpExternalPath(path: string) {
37   return `${httpExternalUri}${path}`;
38 }