Skip to content

Commit

Permalink
Fix dev mode not serving frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
JensForstmann committed Apr 21, 2023
1 parent 7183ecc commit f15f42b
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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();
Expand Down Expand Up @@ -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')));

Expand Down

0 comments on commit f15f42b

Please sign in to comment.