Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor() {
this.app = express();
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);
}
private configureAdminServer() {
this.adminApp = express();
this.adminApp.disable('x-powered-by');
this.adminApp.use(compression());
if (this.config.adminLogger) {
if (!this.config.disableAdminStats) {
this.configureStatsMiddleware(this.adminApp, 'admin');
}
AccessLogger.configureAccessLoger(this.config.adminLogger,
this, this.adminApp, './logs/admin');
}
AdminServer.gateway = this;
Server.buildServices(this.adminApp, ...adminApi);
}
{ from: 'manifests', to: 'manifest' },
{ from: 'revision-history', to: 'revision-history' },
{ from: 'dependents', to: 'dependent' },
{ from: 'resource/policy', to: 'resource/policy' },
];
prefixes.forEach((prefix) => {
app.all(`/${prefix.from}/*`, (req, res, next) => {
req.query['keyPath'] = req.params[0];
req.url = `/${prefix.to}`;
next();
});
});
Server.setFileDest('uploads/');
Server.buildServices(
app,
AppsController,
TagsController,
SearchController,
BulkKeysUpload,
SchemaController,
KeysController,
PolicyController,
ResourcePolicyController,
SubjectExtractionRulesController,
);
return app;
}