Feliday-UI/src/shared/env.ts

37 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()
? `${window.location.hostname}:${
window.location.port == '1234' || window.location.port == '1235'
? 8536
: window.location.port
}`
: 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`;
export const pictrsUri = `${httpBase}/pictrs/image`;
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}`;
}