lemmy-ui/src/shared/env.ts

39 lines
1.1 KiB
TypeScript
Raw Normal View History

import { isBrowser } from './utils';
2020-09-11 18:09:21 +00:00
const testHost = 'localhost:8536';
const internalHost = process.env.LEMMY_INTERNAL_HOST || testHost; // used for local dev
export const externalHost = isBrowser()
2020-10-13 20:43:05 +00:00
? `${window.location.hostname}${
['1234', '1235'].includes(window.location.port)
? ':8536'
2020-10-14 19:37:25 +00:00
: window.location.port == ''
? ''
: `:${window.location.port}`
2020-09-11 18:09:21 +00:00
}`
: process.env.LEMMY_EXTERNAL_HOST || testHost;
2020-09-12 02:37:27 +00:00
const secure = isBrowser()
? window.location.protocol == 'https:'
? 's'
: ''
: process.env.LEMMY_HTTPS == 'true'
? 's'
: '';
2020-09-11 18:09:21 +00:00
const host = isBrowser() ? externalHost : internalHost;
const httpBase = `http://${host}`; // Don't use secure here
2020-09-11 18:09:21 +00:00
export const wsUri = `ws${secure}://${host}/api/v1/ws`;
export const httpUri = `${httpBase}/api/v1`;
2020-09-15 17:54:10 +00:00
export const pictrsUri = `http${secure}://${host}/pictrs/image`;
2020-09-11 18:09:21 +00:00
2020-09-15 15:55:38 +00:00
console.log(`httpbase: ${httpBase}`);
console.log(`wsUri: ${wsUri}`);
2020-09-12 02:37:27 +00:00
// This is for html tags, don't include port
const httpExternalUri = `http${secure}://${externalHost.split(':')[0]}`;
2020-09-11 18:09:21 +00:00
export function httpExternalPath(path: string) {
return `${httpExternalUri}${path}`;
}