fix: don't crash the server if a route fails to load

This commit is contained in:
Zephyrrus 2020-07-20 21:29:06 +03:00
parent 04660dbce1
commit 6fee07d9e1
1 changed files with 7 additions and 3 deletions

View File

@ -70,9 +70,13 @@ class Server {
let routes = [RouteClass];
if (Array.isArray(RouteClass)) routes = RouteClass;
for (const File of routes) {
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}`);
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}`);
} catch (e) {
log.error(`Failed loading route from file ${routeFile} with error: ${e.message}`);
}
}
});
}