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.server = null;
this.PORT = parseInt(process.env.PORT, 0) || 3600;
this.app = express();
this.config();
mongoose.connect(config.db, {
useMongoClient: true,
});
const db = mongoose.connection;
autoIncrement.initialize(db);
db.on('error', (err) => {
throw new Error('unable to connect to database at ' + config.db + err);
});
typescript_rest_1.Server.buildServices(this.app, ...controllers_1.default);
// TODO: enable for Swagger generation error
// Server.loadServices(this.app, 'controllers/*', __dirname);
typescript_rest_1.Server.swagger(this.app, './dist/swagger.json', '/api-docs', 'localhost:3600', ['http']);
this.app.use((err, req, res, next) => {
if (res.headersSent) {
return next(err);
}
if (err && err.statusCode) {
res.status(err.statusCode);
}
else {
res.status(500);
}
res.send({ error: err });
});
}
this.server = null;
this.PORT = parseInt(process.env.PORT, 0) || 3600;
this.app = express();
this.config();
mongoose.connect(config.db, {
useMongoClient: true,
});
const db = mongoose.connection;
autoIncrement.initialize(db);
db.on('error', (err) => {
throw new Error('unable to connect to database at ' + config.db + err);
});
typescript_rest_1.Server.buildServices(this.app, ...controllers_1.default);
// TODO: enable for Swagger generation error
// Server.loadServices(this.app, 'controllers/*', __dirname);
typescript_rest_1.Server.swagger(this.app, './dist/swagger.json', '/api-docs', 'localhost:3600', ['http']);
this.app.use((err, req, res, next) => {
if (res.headersSent) {
return next(err);
}
if (err && err.statusCode) {
res.status(err.statusCode);
}
else {
res.status(500);
}
res.send({ error: err });
});
}
/**
hostSwaggerDocs() {
const swaggerPath = process.env.SWAGGER;
if (fs_1.existsSync(path.resolve(process.env.SWAGGER))) {
typescript_rest_1.Server.swagger(this.app, swaggerPath, '/docs', 'localhost:' + this.PORT, ['http', 'https']);
}
}
config() {
setUploadsFolder() {
const uploads = path.resolve(process.cwd(), 'public', 'uploads');
typescript_rest_1.Server.setFileDest(uploads);
}
hostSwaggerDocs() {
Gateway.prototype.configureAdminServer = function () {
this.adminApp = express();
this.adminApp.disable('x-powered-by');
this.adminApp.use(compression());
this.adminApp.use(logger('dev'));
admin_server_1.APIService.gateway = this;
typescript_rest_1.Server.buildServices(this.adminApp, admin_server_1.APIService);
};
Gateway.prototype.getApiKey = function (api) {