From 6a36f71a98ed03262bf2ab22b089c3677b151505 Mon Sep 17 00:00:00 2001 From: ivaosthu Date: Sat, 24 Nov 2018 12:48:19 +0100 Subject: [PATCH] chore(modernize): Modernize BackstageController --- lib/routes/backstage.js | 26 +++++++++++++++++--------- lib/routes/index.js | 4 ++-- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/lib/routes/backstage.js b/lib/routes/backstage.js index d40945541c..39d7cd5182 100644 --- a/lib/routes/backstage.js +++ b/lib/routes/backstage.js @@ -3,15 +3,23 @@ const { Router } = require('express'); const { register: prometheusRegister } = require('prom-client'); -exports.router = config => { - const router = Router(); +class BackstageController { + constructor(config) { + const router = Router(); - if (config.serverMetrics) { - router.get('/prometheus', (req, res) => { - res.set('Content-Type', prometheusRegister.contentType); - res.end(prometheusRegister.metrics()); - }); + if (config.serverMetrics) { + router.get('/prometheus', (req, res) => { + res.set('Content-Type', prometheusRegister.contentType); + res.end(prometheusRegister.metrics()); + }); + } + + this.app = router; } - return router; -}; + router() { + return this.app; + } +} + +module.exports = BackstageController; diff --git a/lib/routes/index.js b/lib/routes/index.js index b4c237d555..2d5a8bf102 100644 --- a/lib/routes/index.js +++ b/lib/routes/index.js @@ -11,13 +11,13 @@ const clientApi = require('./client-api'); const clientFeatures = require('./client-api/feature.js'); const HealthCheckController = require('./health-check'); -const backstage = require('./backstage.js'); +const BackstageController = require('./backstage.js'); exports.router = function(config) { const router = Router(); router.use('/health', new HealthCheckController(config).router()); - router.use('/internal-backstage', backstage.router(config)); + router.use('/internal-backstage', new BackstageController(config).router()); router.get('/api', (req, res) => { res.json({