aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/config.test.ts7
-rw-r--r--src/util/config.ts9
2 files changed, 11 insertions, 5 deletions
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<MongoClient> =>
- 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<void> => {
export const handleStartup = async (
mongoUri: string,
- hostDir: string,
- publicPath: string,
+ config: EnvConfig,
targetUrl: string
): Promise<MongoClient> => {
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);