briareus
Version:
Briareus assists with Feature Branch deploys to ECS
44 lines (35 loc) • 1.36 kB
JavaScript
const express = require('express');
const mw = require('../middleware');
const controllers = require('../controllers');
module.exports = function (service) {
let server = service.server = express();
// Request Preparation
server.use(mw.jsonBodyParser(service));
server.use(mw.reqContextInit(service));
server.use(mw.requestLogger(service));
server.use(mw.responseLogger(service));
// Application Routes
server.use('/healthcheck', controllers.healthcheck(service));
server.use('/variants/:slug/deployments', mw.findVariant(service), controllers.deployments(service));
server.use('/variants', controllers.variants(service));
server.use('/secrets', controllers.secrets(service));
// Error Handling
server.use(mw.notFound(service));
server.use(mw.errorHandler(service));
// Start web server on application start
service.addHook('start', 'Start HTTP Server', (cb) => {
service.listener = server.listen(service.config.get('port'), (err) => {
if (err) return cb(err);
service.log.info('HTTP server listening on port ' + service.config.get('port'));
cb();
});
});
// Shut down web server on application stop
service.addHook('stop', 'Stop HTTP Server', (cb) => {
service.listener.close(() => {
service.log.info('Closed out remaining connections');
cb();
});
});
}