serve from file instead of object
This commit is contained in:
parent
73b03e28ba
commit
805d19451c
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue