import { matchPath } from 'inferno-router';
import path from 'path';
import { App } from '../shared/components/app';
-import { InitialFetchRequest, IsoData } from '../shared/interfaces';
+import {
+ ILemmyConfig,
+ InitialFetchRequest,
+ IsoData,
+} from '../shared/interfaces';
import { routes } from '../shared/routes';
import IsomorphicCookie from 'isomorphic-cookie';
import { GetSite, LemmyHttp } from 'lemmy-js-client';
const cspStr = process.env.LEMMY_EXTERNAL_HOST ? renderToString(cspHtml) : '';
const helmet = Helmet.renderStatic();
+ const config: ILemmyConfig = { wsHost: process.env.LEMMY_WS_HOST };
+
res.send(`
<!DOCTYPE html>
<html ${helmet.htmlAttributes.toString()} lang="en">
<head>
<script>window.isoData = ${serialize(isoData)}</script>
+ <script>window.lemmyConfig = ${serialize(config)}</script>
${helmet.title.toString()}
${helmet.meta.toString()}
const testHost = 'localhost:8536';
-const internalHost =
+let internalHost =
(!isBrowser() && process.env.LEMMY_INTERNAL_HOST) || testHost; // used for local dev
-export const externalHost = isBrowser()
- ? `${window.location.hostname}${
- ['1234', '1235'].includes(window.location.port)
- ? ':8536'
- : window.location.port == ''
- ? ''
- : `:${window.location.port}`
- }`
- : process.env.LEMMY_EXTERNAL_HOST || testHost;
-
-const secure = isBrowser()
- ? window.location.protocol == 'https:'
- ? 's'
- : ''
- : process.env.LEMMY_HTTPS == 'true'
- ? 's'
- : '';
-
-const host = isBrowser() ? externalHost : internalHost;
+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' : '';
+}
const httpBase = `http://${host}`; // Don't use secure here
-export const wsUri = `ws${secure}://${host}/api/v2/ws`;
+export const wsUri = `ws${secure}://${wsHost}/api/v2/ws`;
export const httpUri = `${httpBase}/api/v2`;
export const pictrsUri = `http${secure}://${host}/pictrs/image`;