Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.config();
mongoose.connect(config.db, {
useMongoClient: true,
});
const db = mongoose.connection;
autoIncrement.initialize(db);
db.on('error', (err: any) => {
throw new Error('unable to connect to database at ' + config.db + err);
});
Server.buildServices(this.app, ...controllers);
// TODO: enable for Swagger generation error
// Server.loadServices(this.app, 'controllers/*', __dirname);
Server.swagger(this.app, './dist/swagger.json', '/api-docs', 'localhost:' + this.PORT, ['http']);
this.app.use((
err: any,
req: express.Request,
res: express.Response, next: any) => {
if (res.headersSent) {
return next(err);
}
if (err && err.statusCode) {
res.status(err.statusCode);
} else {
res.status(500);
}
res.send({ error: err });
});
}
private hostSwaggerDocs() {
const swaggerPath = process.env.SWAGGER;
if (existsSync(path.resolve(process.env.SWAGGER))) {
Server.swagger(
this.app,
swaggerPath,
'/docs',
'localhost:' + this.PORT,
['http', 'https'],
);
}
}