From 5c2f6782ddeafec5503e5b7187420afc503cd865 Mon Sep 17 00:00:00 2001 From: Pitu Date: Fri, 25 Dec 2020 20:09:17 +0900 Subject: Chore: prevent server from starting if .env config missing --- src/api/structures/Server.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/api') diff --git a/src/api/structures/Server.js b/src/api/structures/Server.js index 865419d..cc1064f 100644 --- a/src/api/structures/Server.js +++ b/src/api/structures/Server.js @@ -1,5 +1,10 @@ require('dotenv').config(); +if (!process.env.SERVER_PORT) { + console.log('Run the setup script first or fill the .env file manually before starting'); + process.exit(0); +} + const express = require('express'); const helmet = require('helmet'); const cors = require('cors'); @@ -43,7 +48,9 @@ class Server { }); this.server.use(morgan('combined', { stream: accessLogStream })); } - // this.server.use(rateLimiter); + + // Apply rate limiting to the api only + this.server.use('/api/', rateLimiter); // Serve the uploads this.server.use(express.static(path.join(__dirname, '../../../uploads'))); @@ -52,7 +59,6 @@ class Server { registerAllTheRoutes() { jetpack.find(this.routesFolder, { matching: '*.js' }).forEach(routeFile => { - // eslint-disable-next-line import/no-dynamic-require, global-require const RouteClass = require(path.join('../../../', routeFile)); let routes = [RouteClass]; if (Array.isArray(RouteClass)) routes = RouteClass; -- cgit v1.2.3