1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

chore: Begin converting files from JS to TypeScript

This commit is contained in:
Clint Checketts 2021-02-16 06:30:08 -07:00
parent 35486efe77
commit 6643de66a5
10 changed files with 33 additions and 40 deletions

View File

@ -1,5 +1,3 @@
'use strict';
const express = require('express'); const express = require('express');
const compression = require('compression'); const compression = require('compression');
@ -9,7 +7,7 @@ const path = require('path');
const errorHandler = require('errorhandler'); const errorHandler = require('errorhandler');
const IndexRouter = require('./routes'); const IndexRouter = require('./routes');
const unleashDbSession = require('./middleware/session-db'); const unleashDbSession = require('./middleware/session-db');
const responseTime = require('./middleware/response-time'); import { responseTimeMetrics } from './middleware/response-time-metrics';
const requestLogger = require('./middleware/request-logger'); const requestLogger = require('./middleware/request-logger');
const simpleAuthentication = require('./middleware/simple-authentication'); const simpleAuthentication = require('./middleware/simple-authentication');
const noAuthentication = require('./middleware/no-authentication'); const noAuthentication = require('./middleware/no-authentication');
@ -33,7 +31,7 @@ module.exports = function(config, services = {}) {
app.use(cookieParser()); app.use(cookieParser());
app.use(express.json({ strict: false })); app.use(express.json({ strict: false }));
app.use(unleashDbSession(config)); app.use(unleashDbSession(config));
app.use(responseTime(config)); app.use(responseTimeMetrics(config));
app.use(requestLogger(config)); app.use(requestLogger(config));
app.use(secureHeaders(config)); app.use(secureHeaders(config));
app.use(express.urlencoded({ extended: true })); app.use(express.urlencoded({ extended: true }));

View File

@ -1,3 +0,0 @@
module.exports = {
UNIQUE_CONSTRAINT_VIOLATION: '23505',
};

View File

@ -0,0 +1,3 @@
const UNIQUE_CONSTRAINT_VIOLATION = '23505';
export {UNIQUE_CONSTRAINT_VIOLATION};

View File

@ -1,5 +1,3 @@
'use strict';
class FeatureHasTagError extends Error { class FeatureHasTagError extends Error {
constructor(message) { constructor(message) {
super(); super();
@ -23,4 +21,4 @@ class FeatureHasTagError extends Error {
} }
} }
module.exports = FeatureHasTagError; export {FeatureHasTagError};

View File

@ -1,6 +0,0 @@
'use strict';
module.exports = {
REQUEST_TIME: 'request_time',
DB_TIME: 'db_time',
};

4
src/lib/events.ts Normal file
View File

@ -0,0 +1,4 @@
const REQUEST_TIME = 'request_time';
const DB_TIME = 'db_time';
export {REQUEST_TIME, DB_TIME};

View File

@ -1,19 +1,19 @@
'use strict'; import client from 'prom-client';
import * as events from './events';
const client = require('prom-client'); import {
const events = require('./events');
const {
FEATURE_CREATED, FEATURE_CREATED,
FEATURE_UPDATED, FEATURE_UPDATED,
FEATURE_ARCHIVED, FEATURE_ARCHIVED,
FEATURE_REVIVED, FEATURE_REVIVED,
DB_POOL_UPDATE, DB_POOL_UPDATE,
} = require('./event-type'); } from'./event-type';
const THREE_HOURS = 3 * 60 * 60 * 1000; const THREE_HOURS = 3 * 60 * 60 * 1000;
const ONE_MINUTE = 60 * 1000; const ONE_MINUTE = 60 * 1000;
class MetricsMonitor { class MetricsMonitor {
timer: any;
constructor() { constructor() {
this.timer = null; this.timer = null;
} }
@ -98,16 +98,15 @@ class MetricsMonitor {
}); });
clientMetricsStore.on('metrics', m => { clientMetricsStore.on('metrics', m => {
// eslint-disable-next-line no-restricted-syntax for (const entry of Object.entries(
for (const [feature, { yes, no }] of Object.entries(
m.bucket.toggles, m.bucket.toggles,
)) { )) {
featureToggleUsageTotal featureToggleUsageTotal
.labels(feature, true, m.appName) .labels(entry[0], 'true', m.appName)
.inc(yes); .inc(entry[1]['yes']);
featureToggleUsageTotal featureToggleUsageTotal
.labels(feature, false, m.appName) .labels(entry[0], 'false', m.appName)
.inc(no); .inc(entry[1]['no']);
} }
}); });

View File

@ -1,10 +1,10 @@
'use strict'; import * as responseTime from 'response-time';
import { REQUEST_TIME } from '../events';
const responseTime = require('response-time'); var _responseTime = responseTime.default
const { REQUEST_TIME } = require('../events');
module.exports = function(config) { export function responseTimeMetrics(config) {
return responseTime((req, res, time) => { return _responseTime((req, res, time) => {
const { statusCode } = res; const { statusCode } = res;
const pathname = req.route ? req.baseUrl + req.route.path : '(hidden)'; const pathname = req.route ? req.baseUrl + req.route.path : '(hidden)';

View File

@ -1,9 +1,9 @@
'use strict'; import { register as prometheusRegister } from 'prom-client';
import Controller from './controller';
const { register: prometheusRegister } = require('prom-client');
const Controller = require('./controller');
class BackstageController extends Controller { class BackstageController extends Controller {
logger: any;
constructor(config) { constructor(config) {
super(); super();
@ -18,4 +18,4 @@ class BackstageController extends Controller {
} }
} }
module.exports = BackstageController; export { BackstageController };

View File

@ -6,7 +6,7 @@ const FeatureController = require('./client-api/feature.js');
const Controller = require('./controller'); const Controller = require('./controller');
const HealthCheckController = require('./health-check'); const HealthCheckController = require('./health-check');
const BackstageCTR = require('./backstage.js'); import { BackstageController } from './backstage';
const LogoutController = require('./logout'); const LogoutController = require('./logout');
const api = require('./api-def'); const api = require('./api-def');
@ -14,7 +14,7 @@ class IndexRouter extends Controller {
constructor(config, services) { constructor(config, services) {
super(); super();
this.use('/health', new HealthCheckController(config).router); this.use('/health', new HealthCheckController(config).router);
this.use('/internal-backstage', new BackstageCTR(config).router); this.use('/internal-backstage', new BackstageController(config).router);
this.use('/logout', new LogoutController(config).router); this.use('/logout', new LogoutController(config).router);
this.get(api.uri, this.index); this.get(api.uri, this.index);
this.use(api.links.admin.uri, new AdminApi(config, services).router); this.use(api.links.admin.uri, new AdminApi(config, services).router);