aboutsummaryrefslogtreecommitdiff
path: root/src/api/structures
diff options
context:
space:
mode:
authorPitu <[email protected]>2021-06-15 00:12:26 +0900
committerPitu <[email protected]>2021-06-15 00:12:26 +0900
commitd3c80127ecdc83cffb9ba9a05f47452fec60287c (patch)
treefb056e08947393a6487238b247703565f049a149 /src/api/structures
parentchore: get host from req instead of config (diff)
downloadhost.fuwn.me-d3c80127ecdc83cffb9ba9a05f47452fec60287c.tar.xz
host.fuwn.me-d3c80127ecdc83cffb9ba9a05f47452fec60287c.zip
chore: update process.env usage
Diffstat (limited to 'src/api/structures')
-rw-r--r--src/api/structures/Route.js3
-rw-r--r--src/api/structures/Server.js19
2 files changed, 15 insertions, 7 deletions
diff --git a/src/api/structures/Route.js b/src/api/structures/Route.js
index 24d45b2..9496d0f 100644
--- a/src/api/structures/Route.js
+++ b/src/api/structures/Route.js
@@ -2,6 +2,7 @@ const JWT = require('jsonwebtoken');
const db = require('./Database');
const moment = require('moment');
const log = require('../utils/Log');
+const Util = require('../utils/Util');
class Route {
constructor(path, method, options) {
@@ -30,7 +31,7 @@ class Route {
const token = req.headers.authorization.split(' ')[1];
if (!token) return res.status(401).json({ message: 'No authorization header provided' });
- return JWT.verify(token, process.env.SECRET, async (error, decoded) => {
+ return JWT.verify(token, Util.config.secret, async (error, decoded) => {
if (error) {
log.error(error);
return res.status(401).json({ message: 'Invalid token' });
diff --git a/src/api/structures/Server.js b/src/api/structures/Server.js
index 268ba68..53be9fb 100644
--- a/src/api/structures/Server.js
+++ b/src/api/structures/Server.js
@@ -19,11 +19,10 @@ const CronJob = require('cron').CronJob;
const log = require('../utils/Log');
const Util = require('../utils/Util');
-
// eslint-disable-next-line no-unused-vars
const rateLimiter = new RateLimit({
- windowMs: parseInt(process.env.RATE_LIMIT_WINDOW, 10),
- max: parseInt(process.env.RATE_LIMIT_MAX, 10),
+ windowMs: parseInt(Util.config.rateLimitWindow, 10),
+ max: parseInt(Util.config.rateLimitMax, 10),
delayMs: 0
});
@@ -65,6 +64,7 @@ class Server {
}
registerAllTheRoutes() {
+ console.log(Util.config);
jetpack.find(this.routesFolder, { matching: '*.js' }).forEach(routeFile => {
const RouteClass = require(path.join('../../../', routeFile));
let routes = [RouteClass];
@@ -72,8 +72,8 @@ class Server {
for (const File of routes) {
try {
const route = new File();
- this.server[route.method](process.env.ROUTE_PREFIX + route.path, route.authorize.bind(route));
- log.info(`Found route ${route.method.toUpperCase()} ${process.env.ROUTE_PREFIX}${route.path}`);
+ this.server[route.method](Util.config.routePrefix + route.path, route.authorize.bind(route));
+ log.info(`Found route ${route.method.toUpperCase()} ${Util.config.routePrefix}${route.path}`);
} catch (e) {
log.error(`Failed loading route from file ${routeFile} with error: ${e.message}`);
}
@@ -110,4 +110,11 @@ class Server {
}
}
-new Server().start();
+const start = async () => {
+ const conf = await Util.config;
+ console.log(conf);
+ new Server().start();
+};
+
+start();
+