From fccb1a837b9df060aa379cd16de1275184d9bed5 Mon Sep 17 00:00:00 2001 From: Nawaz Dhandala Date: Sun, 17 Apr 2022 13:12:49 +0100 Subject: [PATCH] fix --- Backend/api/Monitor.ts | 4 +- Backend/utils/flattenArray.ts | 5 ++- ContainerScanner/utils/flattenArray.ts | 7 ++-- Dashboard/src/Utils/flattenArray.ts | 5 ++- DataIngestor/index.ts | 30 -------------- JavaScriptSDK/src/listener.ts | 8 ++-- StatusPage/index.ts | 56 +++----------------------- package.json | 2 +- 8 files changed, 23 insertions(+), 94 deletions(-) diff --git a/Backend/api/Monitor.ts b/Backend/api/Monitor.ts index d1bcb8ec7a..2f4b4d8a79 100755 --- a/Backend/api/Monitor.ts +++ b/Backend/api/Monitor.ts @@ -182,7 +182,7 @@ router.post( const apiResponse: $TSFixMe = await axios(payload); const headerContentType: $TSFixMe = apiResponse.headers['content-type']; - if (/text\/html/.test(headerContentType)) { + if ((/text\/html/).test(headerContentType)) { return sendErrorResponse(req, res, { code: 400, message: @@ -391,7 +391,7 @@ router.put( const apiResponse: $TSFixMe = await axios(payload); const headerContentType: $TSFixMe = apiResponse.headers['content-type']; - if (/text\/html/.test(headerContentType)) { + if ((/text\/html/).test(headerContentType)) { return sendErrorResponse(req, res, { code: 400, message: diff --git a/Backend/utils/flattenArray.ts b/Backend/utils/flattenArray.ts index 082daea065..da3d6475d1 100644 --- a/Backend/utils/flattenArray.ts +++ b/Backend/utils/flattenArray.ts @@ -6,7 +6,7 @@ export default function flat(arr: $TSFixMe): void { const flattened: $TSFixMe = []; - (function flatten(arr: $TSFixMe): void { + const flatten: Function = (arr: $TSFixMe): void => { for (const val of arr) { if (Array.isArray(val)) { flatten(val); @@ -14,6 +14,7 @@ export default function flat(arr: $TSFixMe): void { flattened.push(val); } } - })(arr); + }; + flatten(arr); return flattened; } diff --git a/ContainerScanner/utils/flattenArray.ts b/ContainerScanner/utils/flattenArray.ts index 082daea065..2ec542f59a 100644 --- a/ContainerScanner/utils/flattenArray.ts +++ b/ContainerScanner/utils/flattenArray.ts @@ -4,9 +4,9 @@ * @return {array} a flattened array */ -export default function flat(arr: $TSFixMe): void { + export default function flat(arr: $TSFixMe): void { const flattened: $TSFixMe = []; - (function flatten(arr: $TSFixMe): void { + const flatten: Function = (arr: $TSFixMe): void => { for (const val of arr) { if (Array.isArray(val)) { flatten(val); @@ -14,6 +14,7 @@ export default function flat(arr: $TSFixMe): void { flattened.push(val); } } - })(arr); + }; + flatten(arr); return flattened; } diff --git a/Dashboard/src/Utils/flattenArray.ts b/Dashboard/src/Utils/flattenArray.ts index 082daea065..da3d6475d1 100644 --- a/Dashboard/src/Utils/flattenArray.ts +++ b/Dashboard/src/Utils/flattenArray.ts @@ -6,7 +6,7 @@ export default function flat(arr: $TSFixMe): void { const flattened: $TSFixMe = []; - (function flatten(arr: $TSFixMe): void { + const flatten: Function = (arr: $TSFixMe): void => { for (const val of arr) { if (Array.isArray(val)) { flatten(val); @@ -14,6 +14,7 @@ export default function flat(arr: $TSFixMe): void { flattened.push(val); } } - })(arr); + }; + flatten(arr); return flattened; } diff --git a/DataIngestor/index.ts b/DataIngestor/index.ts index 7a492f5155..6291f34e65 100644 --- a/DataIngestor/index.ts +++ b/DataIngestor/index.ts @@ -1,35 +1,5 @@ -import logger from 'CommonServer/utils/Logger'; import app from 'CommonServer/utils/StartServer'; -import http from 'http'; -http.createServer(app); - -import { mongoUrl, databaseName } from './utils/config'; -const MongoClient: $TSFixMe = require('mongodb').MongoClient; - -// Mongodb -function getMongoClient(): void { - return new MongoClient(mongoUrl, { - useNewUrlParser: true, - useUnifiedTopology: true, - }); -} -// Setup mongodb connection -const client: $TSFixMe = getMongoClient(); -(async function (): void { - try { - logger.info('connecting to db'); - await client.connect(); - logger.info('connected to db'); - } catch (error) { - logger.error('connection error: ', error); - } -})(); - -// Attach the database to global object - -global.db = client.db(databaseName); - app.use(['/data-ingestor/probe', '/probe'], require('./api/probe')); export default app; diff --git a/JavaScriptSDK/src/listener.ts b/JavaScriptSDK/src/listener.ts index 46ad49ba8a..3cf01fb7da 100644 --- a/JavaScriptSDK/src/listener.ts +++ b/JavaScriptSDK/src/listener.ts @@ -50,10 +50,11 @@ class OneUptimeListener { // This will reset the state of the timeline array return this.timelineObj.clearTimeline(); } + // Set up console listener private _setUpConsoleListener(): void { // Set up a console listener get the current content, pass it to the normal console and also pass it to the timeline event listener - const console: Function = (function (oldCons: $TSFixMe): void { + const consoleFunc: Function = (oldCons: $TSFixMe): void => { return { log: function (text: $TSFixMe): void { oldCons.log(text); @@ -81,9 +82,10 @@ class OneUptimeListener { ); }, }; - })(global.console); - //Then redefine the old console + }; + const console = consoleFunc(global.console); + //Then redefine the old console global.console = console; } // Set up dom listener diff --git a/StatusPage/index.ts b/StatusPage/index.ts index 0391f234a9..4ed3cdb61f 100755 --- a/StatusPage/index.ts +++ b/StatusPage/index.ts @@ -8,8 +8,6 @@ import logger from 'CommonServer/Utils/Logger'; import path from 'path'; const app: $TSFixMe = express.getExpressApp(); -import https from 'https'; -import http from 'http'; import tls from 'tls'; import fs from 'fs'; @@ -17,43 +15,6 @@ import fetch from 'node-fetch'; import { spawn } from 'child_process'; import axios from 'axios'; -import cors from 'cors'; - -// Mongodb -const MongoClient: $TSFixMe = require('mongodb').MongoClient; -const mongoUrl: $TSFixMe = - process.env.MONGO_URL || 'mongodb://localhost:27017/oneuptimedb'; - -const { NODE_ENV }: $TSFixMe = process.env; - -function getMongoClient(): void { - return new MongoClient(mongoUrl, { - useNewUrlParser: true, - useUnifiedTopology: true, - }); -} - -// Setup mongodb connection -const client: $TSFixMe = getMongoClient(); -(async function (): void { - try { - logger.info('connecting to db'); - await client.connect(); - - logger.info('connected to db'); - } catch (error) { - logger.info('connection error: ', error); - } -})(); - -if (!NODE_ENV || NODE_ENV === 'development') { - // Load env vars from /StatusPage/.env - import dotenv from 'dotenv'; - dotenv.config(); -} - -app.use(cors()); - let apiHost: $TSFixMe = 'http://localhost:3002/api'; if (process.env.BACKEND_URL) { apiHost = 'http://' + process.env.BACKEND_URL + '/api'; @@ -200,7 +161,7 @@ app.use( try { const response: $TSFixMe = await handleCustomDomain( - client, + global.MongoClient, 'statuspages', host ); @@ -344,12 +305,7 @@ function countFreq(pat: $TSFixMe, txt: $TSFixMe): void { * Using an IIFE here because we have an asynchronous code we want to run as we start the server * And since we can't await outside an async function, we had to use an IIFE to handle that */ -(async function (): void { - // Create http server - http.createServer(app).listen(3006, () => { - return logger.info('Server running on port 3006'); - }); - +const setupCerts: Function = async (): void => { try { // Create https server await createDir('credentials'); @@ -521,13 +477,11 @@ function countFreq(pat: $TSFixMe, txt: $TSFixMe): void { ); }, }; - - https.createServer(options, app).listen(3007, () => { - logger.info('Server running on port 3007'); - }); } catch (e) { logger.info('Unable to create HTTPS Server'); logger.info(e); } -})(); +}; + +setupCerts(); diff --git a/package.json b/package.json index 5378756f20..05350fb8b1 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "uninstall": "docker stop $(docker ps -a -q) && docker rm $(docker ps -a -q)", "delete-all-local-branches": "git branch | grep -v 'master' | xargs git branch -D", "lint": "ejslint home/views/*.ejs && eslint '**/*.ts' -c .eslintrc.json --ignore-path .eslintignore", - "fix-lint": "eslint --fix '**/*.ts' -c .eslintrc.json --ignore-path .eslintignore", + "fix-lint": "eslint '**/*.ts' -c .eslintrc.json --ignore-path .eslintignore --fix", "fix": "npm run fix-lint", "build": "docker-compose --env-file ./docker-enterprise.env build", "build-dev": "docker-compose --env-file ./docker-enterprise.env -f docker-compose.dev.yml build $npm_config_services",