From c114e59be329fa9ceb8f1f8e79356a0e3afbd1ae Mon Sep 17 00:00:00 2001 From: Pitu Date: Sat, 9 May 2020 19:21:20 +0900 Subject: Feature: * Frontend is now served by the API process * Only 1 process spawns for lolisafe to work * Switched frontend from server-side render to static site, now saved in `/dist` --- src/api/structures/Server.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/api/structures/Server.js') diff --git a/src/api/structures/Server.js b/src/api/structures/Server.js index 50f6754..c80c44f 100644 --- a/src/api/structures/Server.js +++ b/src/api/structures/Server.js @@ -23,16 +23,23 @@ class Server { this.server.use(helmet()); this.server.use(cors({ allowedHeaders: ['Accept', 'Authorization', 'Cache-Control', 'X-Requested-With', 'Content-Type', 'albumId'] })); this.server.use((req, res, next) => { - /* - This bypasses the headers.accept for album download, since it's accesed directly through the browser. - */ + // This bypasses the headers.accept for album download, since it's accesed directly through the browser. if ((req.url.includes('/api/album/') || req.url.includes('/zip')) && req.method === 'GET') return next(); + // This bypasses the headers.accept if we are accessing the frontend + if (!req.url.includes('/api/') && req.method === 'GET') return next(); if (req.headers.accept && req.headers.accept.includes('application/vnd.lolisafe.json')) return next(); return res.status(405).json({ message: 'Incorrect `Accept` header provided' }); }); this.server.use(bodyParser.urlencoded({ extended: true })); this.server.use(bodyParser.json()); // this.server.use(rateLimiter); + + // Serve the frontend if we are in production mode + if (process.env.NODE_ENV === 'production') { + this.server.use(express.static(path.join(__dirname, '..', '..', '..', 'dist'))); + this.server.use(express.static(path.join(__dirname, '..', '..', '..', 'uploads'))); + } + this.routesFolder = path.join(__dirname, '..', 'routes'); } -- cgit v1.2.3