diff --git a/config.yml b/config.yml index 3e9088a..b8efbf9 100644 --- a/config.yml +++ b/config.yml @@ -8,7 +8,7 @@ endpoints: - key: "Content-Type" value: "application/json" - key: "Authorization" - value: "Bearer 1234567890" + value: "Bearer ${AUTH_TOKEN}" - name: "todos-post" path: "/todos" method: "POST" @@ -18,7 +18,7 @@ endpoints: - key: "Content-Type" value: "application/json" - key: "Authorization" - value: "Bearer 1234567890" + value: "Bearer ${AUTH_TOKEN}" - name: "posts" path: "/posts" method: "GET" diff --git a/src/index.ts b/src/index.ts index f3d2eca..9f0b110 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,11 +1,15 @@ +import "dotenv/config"; import express from "express"; +import { parseConfig } from "./utils/config/parse-config"; const app = express(); const PORT = process.env.PORT || 6060; app.get("/", (req, res) => { - res.send("Hello World"); + const config = parseConfig("config.yml"); + + res.send(config); }); app.listen(PORT, () => { diff --git a/src/utils/config/parse-config.ts b/src/utils/config/parse-config.ts index e10550c..9a92439 100644 --- a/src/utils/config/parse-config.ts +++ b/src/utils/config/parse-config.ts @@ -4,8 +4,11 @@ import { Config } from "../../types/config"; import { validateConfig } from "./validate-config"; export const parseConfig = (filePath: string): Config => { - const file = fs.readFileSync(filePath, "utf8"); - const config = YAML.parse(file); + const fileContents = fs + .readFileSync(filePath, "utf8") + .replace(/\$\{(.+?)\}/g, (match, name) => process.env[name] || match); + + const config = YAML.parse(fileContents); const valid = validateConfig(config);