2020-09-09 22:07:58 +00:00
|
|
|
import { isBrowser } from './utils';
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2020-09-11 18:09:21 +00:00
|
|
|
const testHost = 'localhost:8536';
|
|
|
|
|
2021-02-12 17:54:35 +00:00
|
|
|
let internalHost =
|
2020-10-24 17:12:13 +00:00
|
|
|
(!isBrowser() && process.env.LEMMY_INTERNAL_HOST) || testHost; // used for local dev
|
2021-02-12 17:54:35 +00:00
|
|
|
export let externalHost: string;
|
|
|
|
let host: string;
|
|
|
|
let wsHost: string;
|
|
|
|
let secure: string;
|
|
|
|
|
|
|
|
if (isBrowser()) {
|
|
|
|
// browser
|
|
|
|
const lemmyConfig =
|
|
|
|
typeof window.lemmyConfig !== 'undefined' ? window.lemmyConfig : {};
|
|
|
|
|
|
|
|
externalHost = `${window.location.hostname}${
|
|
|
|
['1234', '1235'].includes(window.location.port)
|
|
|
|
? ':8536'
|
|
|
|
: window.location.port == ''
|
|
|
|
? ''
|
|
|
|
: `:${window.location.port}`
|
|
|
|
}`;
|
|
|
|
|
|
|
|
host = externalHost;
|
|
|
|
wsHost = lemmyConfig.wsHost || host;
|
|
|
|
secure = window.location.protocol == 'https:' ? 's' : '';
|
|
|
|
} else {
|
|
|
|
// server-side
|
|
|
|
externalHost = process.env.LEMMY_EXTERNAL_HOST || testHost;
|
|
|
|
host = internalHost;
|
|
|
|
wsHost = process.env.LEMMY_WS_HOST || host;
|
|
|
|
secure = process.env.LEMMY_HTTPS == 'true' ? 's' : '';
|
|
|
|
}
|
2020-09-11 18:09:21 +00:00
|
|
|
|
2020-09-15 15:26:59 +00:00
|
|
|
const httpBase = `http://${host}`; // Don't use secure here
|
2021-02-12 17:54:35 +00:00
|
|
|
export const wsUri = `ws${secure}://${wsHost}/api/v2/ws`;
|
2020-12-24 22:05:57 +00:00
|
|
|
export const httpUri = `${httpBase}/api/v2`;
|
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}`;
|
|
|
|
}
|