Skip to content

Commit

Permalink
add WS_STATIC_ROOT
Browse files Browse the repository at this point in the history
  • Loading branch information
mat-sz committed Oct 27, 2023
1 parent 643fadd commit 95d1b74
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions ws/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
13 changes: 10 additions & 3 deletions ws/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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('/');
Expand Down

0 comments on commit 95d1b74

Please sign in to comment.