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:
parent
35486efe77
commit
6643de66a5
@ -1,5 +1,3 @@
|
||||
'use strict';
|
||||
|
||||
const express = require('express');
|
||||
|
||||
const compression = require('compression');
|
||||
@ -9,7 +7,7 @@ const path = require('path');
|
||||
const errorHandler = require('errorhandler');
|
||||
const IndexRouter = require('./routes');
|
||||
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 simpleAuthentication = require('./middleware/simple-authentication');
|
||||
const noAuthentication = require('./middleware/no-authentication');
|
||||
@ -33,7 +31,7 @@ module.exports = function(config, services = {}) {
|
||||
app.use(cookieParser());
|
||||
app.use(express.json({ strict: false }));
|
||||
app.use(unleashDbSession(config));
|
||||
app.use(responseTime(config));
|
||||
app.use(responseTimeMetrics(config));
|
||||
app.use(requestLogger(config));
|
||||
app.use(secureHeaders(config));
|
||||
app.use(express.urlencoded({ extended: true }));
|
@ -1,3 +0,0 @@
|
||||
module.exports = {
|
||||
UNIQUE_CONSTRAINT_VIOLATION: '23505',
|
||||
};
|
3
src/lib/error/db-error.ts
Normal file
3
src/lib/error/db-error.ts
Normal file
@ -0,0 +1,3 @@
|
||||
const UNIQUE_CONSTRAINT_VIOLATION = '23505';
|
||||
|
||||
export {UNIQUE_CONSTRAINT_VIOLATION};
|
@ -1,5 +1,3 @@
|
||||
'use strict';
|
||||
|
||||
class FeatureHasTagError extends Error {
|
||||
constructor(message) {
|
||||
super();
|
||||
@ -23,4 +21,4 @@ class FeatureHasTagError extends Error {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = FeatureHasTagError;
|
||||
export {FeatureHasTagError};
|
@ -1,6 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
REQUEST_TIME: 'request_time',
|
||||
DB_TIME: 'db_time',
|
||||
};
|
4
src/lib/events.ts
Normal file
4
src/lib/events.ts
Normal file
@ -0,0 +1,4 @@
|
||||
const REQUEST_TIME = 'request_time';
|
||||
const DB_TIME = 'db_time';
|
||||
|
||||
export {REQUEST_TIME, DB_TIME};
|
@ -1,19 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
const client = require('prom-client');
|
||||
const events = require('./events');
|
||||
const {
|
||||
import client from 'prom-client';
|
||||
import * as events from './events';
|
||||
import {
|
||||
FEATURE_CREATED,
|
||||
FEATURE_UPDATED,
|
||||
FEATURE_ARCHIVED,
|
||||
FEATURE_REVIVED,
|
||||
DB_POOL_UPDATE,
|
||||
} = require('./event-type');
|
||||
} from'./event-type';
|
||||
|
||||
const THREE_HOURS = 3 * 60 * 60 * 1000;
|
||||
const ONE_MINUTE = 60 * 1000;
|
||||
|
||||
class MetricsMonitor {
|
||||
timer: any;
|
||||
|
||||
constructor() {
|
||||
this.timer = null;
|
||||
}
|
||||
@ -98,16 +98,15 @@ class MetricsMonitor {
|
||||
});
|
||||
|
||||
clientMetricsStore.on('metrics', m => {
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (const [feature, { yes, no }] of Object.entries(
|
||||
for (const entry of Object.entries(
|
||||
m.bucket.toggles,
|
||||
)) {
|
||||
featureToggleUsageTotal
|
||||
.labels(feature, true, m.appName)
|
||||
.inc(yes);
|
||||
.labels(entry[0], 'true', m.appName)
|
||||
.inc(entry[1]['yes']);
|
||||
featureToggleUsageTotal
|
||||
.labels(feature, false, m.appName)
|
||||
.inc(no);
|
||||
.labels(entry[0], 'false', m.appName)
|
||||
.inc(entry[1]['no']);
|
||||
}
|
||||
});
|
||||
|
@ -1,10 +1,10 @@
|
||||
'use strict';
|
||||
import * as responseTime from 'response-time';
|
||||
import { REQUEST_TIME } from '../events';
|
||||
|
||||
const responseTime = require('response-time');
|
||||
const { REQUEST_TIME } = require('../events');
|
||||
var _responseTime = responseTime.default
|
||||
|
||||
module.exports = function(config) {
|
||||
return responseTime((req, res, time) => {
|
||||
export function responseTimeMetrics(config) {
|
||||
return _responseTime((req, res, time) => {
|
||||
const { statusCode } = res;
|
||||
|
||||
const pathname = req.route ? req.baseUrl + req.route.path : '(hidden)';
|
@ -1,9 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
const { register: prometheusRegister } = require('prom-client');
|
||||
const Controller = require('./controller');
|
||||
import { register as prometheusRegister } from 'prom-client';
|
||||
import Controller from './controller';
|
||||
|
||||
class BackstageController extends Controller {
|
||||
logger: any;
|
||||
|
||||
constructor(config) {
|
||||
super();
|
||||
|
||||
@ -18,4 +18,4 @@ class BackstageController extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BackstageController;
|
||||
export { BackstageController };
|
@ -6,7 +6,7 @@ const FeatureController = require('./client-api/feature.js');
|
||||
|
||||
const Controller = require('./controller');
|
||||
const HealthCheckController = require('./health-check');
|
||||
const BackstageCTR = require('./backstage.js');
|
||||
import { BackstageController } from './backstage';
|
||||
const LogoutController = require('./logout');
|
||||
const api = require('./api-def');
|
||||
|
||||
@ -14,7 +14,7 @@ class IndexRouter extends Controller {
|
||||
constructor(config, services) {
|
||||
super();
|
||||
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.get(api.uri, this.index);
|
||||
this.use(api.links.admin.uri, new AdminApi(config, services).router);
|
Loading…
Reference in New Issue
Block a user