feat: Serve react app through express server

This commit is contained in:
Faruk AYDIN
2022-02-23 21:24:21 +03:00
committed by Ömer Faruk Aydın
parent d139eb8c06
commit 654e868a23
7 changed files with 55 additions and 24 deletions

View File

@@ -0,0 +1,16 @@
import express, { Application } from 'express';
import { dirname, join } from 'path';
import appConfig from '../config/app';
const webUIHandler = async (app: Application) => {
if (appConfig.serveWebAppSeparately) return;
const webAppPath = require.resolve('@automatisch/web');
const webBuildPath = join(dirname(webAppPath), 'build');
const indexHtml = join(dirname(webAppPath), 'build', 'index.html');
app.use(express.static(webBuildPath));
app.get('*', (_req, res) => res.sendFile(indexHtml));
};
export default webUIHandler;