diff options
author | Alan Pearce | 2023-09-11 19:43:06 +0200 |
---|---|---|
committer | Alan Pearce | 2023-09-11 19:43:06 +0200 |
commit | 51cc4389f6dc7947ee34d1b3367876941e8a8fbc (patch) | |
tree | 300ad6bc3cdfcdbbc73e7a543e0807c2da6b7785 | |
parent | a25028aa30bf0f3b89a9a7c99192e1a14267fc97 (diff) | |
download | homestead-51cc4389f6dc7947ee34d1b3367876941e8a8fbc.tar.lz homestead-51cc4389f6dc7947ee34d1b3367876941e8a8fbc.tar.zst homestead-51cc4389f6dc7947ee34d1b3367876941e8a8fbc.zip |
Serve static files
-rw-r--r-- | README.md | 5 | ||||
-rwxr-xr-x | bun.lockb | bin | 2354 -> 2042 bytes | |||
-rw-r--r-- | package.json | 2 | ||||
-rw-r--r-- | src/index.ts | 12 | ||||
-rw-r--r-- | test/index.test.ts | 9 |
5 files changed, 18 insertions, 10 deletions
diff --git a/README.md b/README.md index 3430625..34f3f42 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,9 @@ ## Goals -1. To be a near-drop-in replacement for Zola -2. More indieweb features +1. Static web server with prometheus-based analytics +2. Dynamic web server capable of generating Zola-based websites +3. More indieweb features ## Installing diff --git a/bun.lockb b/bun.lockb index 2ab9dd9..f724266 100755 --- a/bun.lockb +++ b/bun.lockb Binary files differdiff --git a/package.json b/package.json index 96a8252..d0e61be 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,6 @@ }, "type": "module", "dependencies": { - "siopao": "^0.4.0" + "serve-static-bun": "^0.5.3" } } \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 8c0a3ba..59913b3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,10 +1,10 @@ -import { withHtmlLiveReload } from "bun-html-live-reload"; -import Siopao from "siopao"; +import { withHtmlLiveReload } from "bun-html-live-reload" +import serveStatic from "serve-static-bun" -const router = new Siopao(); - -router.get("/status", () => new Response("OK")); +const dir = Bun.argv.length > 2 ? Bun.argv[Bun.argv.length - 1] : "./" export default withHtmlLiveReload({ - fetch: router.fetch.bind(router), + fetch: serveStatic(dir, { + dotfiles: "allow" + }), }) diff --git a/test/index.test.ts b/test/index.test.ts index d82cb9e..8a32e47 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -4,6 +4,7 @@ import { expect, test, beforeAll, afterAll } from "bun:test" import app from "../src/index" const port = 33000; +const base = `http://localhost:${port}/`; let server: Server beforeAll(async function () { @@ -15,7 +16,13 @@ afterAll(function () { }) test("/status returns 200 OK", async function () { - const res = await fetch(`http://localhost:${port}/status`) + const res = await fetch(new URL("/status", base)) expect(res.status).toBe(200) expect(await res.text()).toBe("OK") }) + +test("/ returns 200 and says Hello world", async function () { + const res = await fetch(base) + expect(res.status).toBe(200) + expect(await res.text()).toBe("Hello world") +}) |