diff options
| author | Pitu <[email protected]> | 2020-12-25 20:09:17 +0900 |
|---|---|---|
| committer | Pitu <[email protected]> | 2020-12-25 20:09:17 +0900 |
| commit | 5c2f6782ddeafec5503e5b7187420afc503cd865 (patch) | |
| tree | c828be5f497832c61a441a412f588f91e269947c /src/api/structures | |
| parent | Update ESLint (diff) | |
| download | host.fuwn.me-5c2f6782ddeafec5503e5b7187420afc503cd865.tar.xz host.fuwn.me-5c2f6782ddeafec5503e5b7187420afc503cd865.zip | |
Chore: prevent server from starting if .env config missing
Diffstat (limited to 'src/api/structures')
| -rw-r--r-- | src/api/structures/Server.js | 10 |
1 files changed, 8 insertions, 2 deletions
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; |