aboutsummaryrefslogtreecommitdiff
path: root/src/api/structures/Server.js
diff options
context:
space:
mode:
authorPitu <[email protected]>2020-05-09 19:21:20 +0900
committerPitu <[email protected]>2020-05-09 19:21:20 +0900
commitc114e59be329fa9ceb8f1f8e79356a0e3afbd1ae (patch)
treea9166ef288e882452815ed1889186f2fda6b2588 /src/api/structures/Server.js
parentwip: (diff)
downloadhost.fuwn.me-c114e59be329fa9ceb8f1f8e79356a0e3afbd1ae.tar.xz
host.fuwn.me-c114e59be329fa9ceb8f1f8e79356a0e3afbd1ae.zip
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`
Diffstat (limited to 'src/api/structures/Server.js')
-rw-r--r--src/api/structures/Server.js13
1 files changed, 10 insertions, 3 deletions
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');
}