From f830bab4ec14f3fe814962a6a2dee180149c3a6a Mon Sep 17 00:00:00 2001 From: Kevin J Hoerr Date: Mon, 20 Sep 2021 19:43:18 +0000 Subject: The Whole Barnshow Commit - Use yarn-berry instead of npm, with Zero Install feature and goodies - Add `initializeToken` to post unique token to logs on startup - Package upgrades - Fix index.html.template tests I will never do this again --- src/util/config.ts | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'src/util/config.ts') diff --git a/src/util/config.ts b/src/util/config.ts index 3b09590..e83eab7 100644 --- a/src/util/config.ts +++ b/src/util/config.ts @@ -3,6 +3,7 @@ import { MongoClient, MongoError } from "mongodb"; import { Server } from "http"; import path from "path"; import fs from "fs"; +import { v4 as uuid } from "uuid"; import loggerConfig from "./logger"; import processTemplate, { Template } from "../templates"; @@ -10,6 +11,21 @@ import { EnvConfig } from "../metadata"; const logger = winston.createLogger(loggerConfig("ROOT")); +export const initializeToken = (): string => { + //TODO check for token in hostDir/persist created token in hostDir so it's not regenerated on startup + const newToken = uuid(); + + logger.warn( + "TOKEN variable not provided, using this value instead: %s", + newToken + ); + logger.warn( + "Use this provided token to push your coverage reports to the server." + ); + + return newToken; +}; + export const configOrError = (varName: string): string => { const value = process.env[varName]; if (value !== undefined) { @@ -58,9 +74,7 @@ export const handleStartup = async ( await Promise.reject("hostDir must be an absolute path"); } - const mongo = await MongoClient.connect(mongoUri, { - useUnifiedTopology: true - }).catch((err: MongoError) => + const mongo = await MongoClient.connect(mongoUri).catch((err: MongoError) => Promise.reject(err.message ?? "Unable to connect to database") ); -- cgit