all repos — archive/homestead @ 78439b16cc66532225e75c9aa40cf7c49cddc22d

My future indieweb platform

Read config from TOML file

Alan Pearce
commit

78439b16cc66532225e75c9aa40cf7c49cddc22d

parent

b45b4e37af14d94726b0c5d2691289886c0527cf

4 files changed, 19 insertions(+), 3 deletions(-)

jump to
M bun.lockbbun.lockb

Not showing binary file.

M package.jsonpackage.json
@@ -10,6 +10,7 @@ "typescript": "^5.0.0"
}, "type": "module", "dependencies": { - "serve-static-bun": "^0.5.3" + "serve-static-bun": "^0.5.3", + "toml": "^3.0.0" } }
A src/config.ts
@@ -0,0 +1,9 @@
+import path from "node:path"; +import fs from "node:fs"; +import toml from "toml"; + +export default function readConfig(base: string) { + const filename = path.join(base, "config.toml"); + + return toml.parse(fs.readFileSync(filename, "utf-8")); +}
M src/index.tssrc/index.ts
@@ -1,10 +1,16 @@
+import path from "node:path"; import { withHtmlLiveReload } from "bun-html-live-reload"; import serveStatic from "serve-static-bun"; -const dir = Bun.argv.length > 2 ? Bun.argv[Bun.argv.length - 1] : "./"; +import readConfig from "./config"; + +const base = Bun.argv.length > 2 ? Bun.argv[Bun.argv.length - 1] : "."; + +const config = readConfig(base); export default withHtmlLiveReload({ - fetch: serveStatic(dir, { + fetch: serveStatic(path.join(base, "public"), { + headers: config.extra.headers, dotfiles: "allow", }), });