From 805d19451c18da076d9039fb897fd1738fcc9786 Mon Sep 17 00:00:00 2001 From: eko Date: Tue, 2 Dec 2025 16:08:22 +0700 Subject: [PATCH] serve from file instead of object --- pkgs/server/create.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pkgs/server/create.ts b/pkgs/server/create.ts index f9ad41c..8b4469f 100644 --- a/pkgs/server/create.ts +++ b/pkgs/server/create.ts @@ -10,6 +10,7 @@ import { parseArgs } from "./parse-args"; import { serveAPI } from "./serve-api"; import { serveWeb } from "./serve-web"; import exitHook from "exit-hook"; +import { fileTypeFromBlob } from "file-type"; export const createServer = async () => { console.log(`[DEBUG] Starting server creation...`); @@ -192,7 +193,16 @@ export const createServer = async () => { if (core[pathname]) content = core[pathname]; else if (site[pathname]) content = site[pathname]; - else if (pub[pathname]) content = pub[pathname]; + else if (pub[pathname]){ + //read content from file + content = await Bun.file(dir(`public/${pathname}`)).text(); + //detect file type + const fileType = await fileTypeFromBlob(Bun.file(dir(`public/${pathname}`))); + if(fileType){ + //set content type + opt?.headers?.set("Content-Type", fileType.mime); + } + }