From f15f42b39b1dae9a943dd5857862061fd069f979 Mon Sep 17 00:00:00 2001 From: JensForstmann <19289807+JensForstmann@users.noreply.github.com> Date: Fri, 21 Apr 2023 23:17:49 +0200 Subject: [PATCH] Fix dev mode not serving frontend --- backend/src/index.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/backend/src/index.ts b/backend/src/index.ts index d4d3cda..4dd7166 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -2,6 +2,7 @@ import { ValidateError } from '@tsoa/runtime'; import express, { ErrorRequestHandler } from 'express'; import path from 'path'; import http from 'http'; +import { existsSync } from 'fs'; import * as Auth from './auth'; import * as MatchService from './matchService'; import * as ManagedGameServers from './managedGameServers'; @@ -23,6 +24,16 @@ export const TMT_LOG_ADDRESS: string | null = (() => { return addr; })(); +const STATIC_PATH = (() => { + if (existsSync(path.join(__dirname, '../../frontend/dist'))) { + return path.join(__dirname, '../../frontend/dist'); + } + if (existsSync(path.join(__dirname, '../../../../frontend/dist'))) { + return path.join(__dirname, '../../../../frontend/dist'); + } + throw 'Could not determine static path'; +})(); + const PORT = process.env['TMT_PORT'] || 8080; const app = express(); @@ -87,7 +98,6 @@ app.get('/api', (req, res) => { res.sendFile('swagger.json', { root: '.' }); }); -const STATIC_PATH = path.join(__dirname, '../../../../frontend/dist'); app.get('*', express.static(STATIC_PATH)); app.get('*', (req, res) => res.sendFile(path.join(STATIC_PATH, 'index.html')));