refactor: serve react as compressed br (#339)

This commit is contained in:
Carlos Valente
2023-04-15 13:27:29 +02:00
committed by GitHub
parent 6732314f15
commit 11663e5416
5 changed files with 33 additions and 2 deletions
+9 -2
View File
@@ -1,5 +1,6 @@
import 'dotenv/config';
import express from 'express';
import expressStaticGzip from 'express-static-gzip';
import http from 'http';
import cors from 'cors';
@@ -61,8 +62,14 @@ app.use('/playback', playbackRouter);
// serve static - css
app.use('/external', express.static(externalsStartDirectory));
// serve static - react, in test mode we fetch the React app from module
app.use(express.static(join(currentDirectory, resolvedPath())));
// serve static - react, in dev/test mode we fetch the React app from module
const reactAppPath = join(currentDirectory, resolvedPath());
app.use(
expressStaticGzip(reactAppPath, {
enableBrotli: true,
orderPreference: ['br'],
}),
);
app.get('*', (req, res) => {
res.sendFile(resolve(currentDirectory, resolvedPath(), 'index.html'));