From b659864f7a60e624f893c9ba7834e54af75d7a16 Mon Sep 17 00:00:00 2001 From: Kevin J Hoerr Date: Sun, 12 Sep 2021 10:08:51 -0400 Subject: Refactor env config into Metadata --- src/util/config.test.ts | 7 ++++++- src/util/config.ts | 9 +++++---- 2 files changed, 11 insertions(+), 5 deletions(-) (limited to 'src/util') diff --git a/src/util/config.test.ts b/src/util/config.test.ts index 7506840..e385bce 100644 --- a/src/util/config.test.ts +++ b/src/util/config.test.ts @@ -13,6 +13,7 @@ import { Server } from "http"; import path from "path"; import fs from "fs"; import * as templates from "../templates"; +import { EnvConfig } from "../metadata"; const CommonMocks = { connect: jest.fn(), @@ -188,8 +189,12 @@ describe("handleStartup", () => { exit.mockClear(); }); + const config = { + hostDir: "/apple", + publicDir: "/public" + } as EnvConfig; const confStartup = (): Promise => - handleStartup("", "/apple", "/public", "localhost"); + handleStartup("", config, "localhost"); it("should pass back MongoClient", async () => { const superClient = {} as MongoClient; diff --git a/src/util/config.ts b/src/util/config.ts index 3f14db1..a0de761 100644 --- a/src/util/config.ts +++ b/src/util/config.ts @@ -6,6 +6,7 @@ import fs from "fs"; import loggerConfig from "./logger"; import processTemplate, { Template } from "../templates"; +import { EnvConfig } from "../metadata"; const logger = winston.createLogger(loggerConfig("ROOT")); @@ -47,11 +48,11 @@ export const persistTemplate = async (input: Template): Promise => { export const handleStartup = async ( mongoUri: string, - hostDir: string, - publicPath: string, + config: EnvConfig, targetUrl: string ): Promise => { try { + const { hostDir, publicDir } = config; await fs.promises.access(hostDir, fs.constants.R_OK | fs.constants.W_OK); if (!path.isAbsolute(hostDir)) { await Promise.reject("hostDir must be an absolute path"); @@ -64,12 +65,12 @@ export const handleStartup = async ( ); await persistTemplate({ - inputFile: path.join(publicPath, "templates", "bash.template"), + inputFile: path.join(publicDir, "templates", "bash.template"), outputFile: path.join(hostDir, "bash"), context: { TARGET_URL: targetUrl } } as Template); await persistTemplate({ - inputFile: path.join(publicPath, "templates", "index.html.template"), + inputFile: path.join(publicDir, "templates", "index.html.template"), outputFile: path.join(hostDir, "index.html"), context: { TARGET_URL: targetUrl } } as Template); -- cgit