diff --git a/ws/src/config.ts b/ws/src/config.ts index d8031f2..b1db052 100644 --- a/ws/src/config.ts +++ b/ws/src/config.ts @@ -6,6 +6,7 @@ export const host = process.env.WS_HOST || '127.0.0.1'; export const port = parseInt(process.env.WS_PORT || '5000'); export const appName = process.env.WS_APP_NAME || undefined; export const abuseEmail = process.env.WS_ABUSE_EMAIL || undefined; +export const staticRoot = process.env.WS_STATIC_ROOT || '../web/build'; export const maxClientNameLength = 32; export const maxSize = parseInt(process.env.WS_MAX_SIZE || '65536'); diff --git a/ws/src/index.ts b/ws/src/index.ts index f62677a..ab88cea 100755 --- a/ws/src/index.ts +++ b/ws/src/index.ts @@ -2,13 +2,19 @@ import path, { resolve } from 'path'; import Fastify from 'fastify'; import fastifyWebsocket from '@fastify/websocket'; import fastifyStatic from '@fastify/static'; -import fastifyHttpProxy from '@fastify/http-proxy'; import fastifyCompress from '@fastify/compress'; import { WSClient } from './WSClient.js'; import { ClientManager } from './ClientManager.js'; import { isMessageModel } from './utils/validation.js'; -import { host, maxSize, port, useProxy, appName } from './config.js'; +import { + host, + maxSize, + port, + useProxy, + appName, + staticRoot, +} from './config.js'; const clientManager = new ClientManager(); const app = Fastify(); @@ -33,11 +39,12 @@ const manifestString = JSON.stringify(manifest); const maxAge = 30 * 24 * 60 * 60 * 1000; if (useProxy) { + const fastifyHttpProxy = (await import('@fastify/http-proxy')).default; app.register(fastifyHttpProxy, { upstream: 'http://localhost:3000/', }); } else { - const STATIC_ROOT = resolve('../web/build'); + const STATIC_ROOT = resolve(staticRoot); app.setNotFoundHandler((req, reply) => { const split = req.url.split('/');