diff options
author | Alan Pearce | 2023-09-12 10:56:39 +0200 |
---|---|---|
committer | Alan Pearce | 2023-09-12 10:56:39 +0200 |
commit | 78439b16cc66532225e75c9aa40cf7c49cddc22d (patch) | |
tree | 24514d56345534ad50ad6180026d67b605fea071 | |
parent | b45b4e37af14d94726b0c5d2691289886c0527cf (diff) | |
download | homestead-78439b16cc66532225e75c9aa40cf7c49cddc22d.tar.lz homestead-78439b16cc66532225e75c9aa40cf7c49cddc22d.tar.zst homestead-78439b16cc66532225e75c9aa40cf7c49cddc22d.zip |
Read config from TOML file
-rwxr-xr-x | bun.lockb | bin | 2042 -> 2386 bytes | |||
-rw-r--r-- | package.json | 3 | ||||
-rw-r--r-- | src/config.ts | 9 | ||||
-rw-r--r-- | src/index.ts | 10 |
4 files changed, 19 insertions, 3 deletions
diff --git a/bun.lockb b/bun.lockb index f724266..c8b2651 100755 --- a/bun.lockb +++ b/bun.lockb Binary files differdiff --git a/package.json b/package.json index d0e61be..27f95e0 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ }, "type": "module", "dependencies": { - "serve-static-bun": "^0.5.3" + "serve-static-bun": "^0.5.3", + "toml": "^3.0.0" } } \ No newline at end of file diff --git a/src/config.ts b/src/config.ts new file mode 100644 index 0000000..064b038 --- /dev/null +++ b/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")); +} diff --git a/src/index.ts b/src/index.ts index 4887dd6..d8c9bf1 100644 --- a/src/index.ts +++ b/src/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", }), }); |