serve file manually
This commit is contained in:
parent
998d8b3b31
commit
2263f15fa6
|
|
@ -204,33 +204,6 @@ export const createServer = async () => {
|
|||
return new Response("File not found", { status: 404 });
|
||||
}
|
||||
|
||||
// Detect file type
|
||||
const fileType = await fileTypeFromBlob(file);
|
||||
|
||||
// Set content type
|
||||
if (fileType) {
|
||||
opt?.headers?.set("Content-Type", fileType.mime);
|
||||
} else {
|
||||
// Fallback to extension-based MIME type detection
|
||||
const ext = pathname.split('.').pop()?.toLowerCase();
|
||||
const mimeTypes: Record<string, string> = {
|
||||
'html': 'text/html',
|
||||
'css': 'text/css',
|
||||
'js': 'application/javascript',
|
||||
'json': 'application/json',
|
||||
'png': 'image/png',
|
||||
'jpg': 'image/jpeg',
|
||||
'jpeg': 'image/jpeg',
|
||||
'gif': 'image/gif',
|
||||
'svg': 'image/svg+xml',
|
||||
'ico': 'image/x-icon',
|
||||
'txt': 'text/plain',
|
||||
};
|
||||
if (ext && mimeTypes[ext]) {
|
||||
opt?.headers?.set("Content-Type", mimeTypes[ext]);
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`[DEBUG] Serving file: ${pathname} with content type: ${opt?.headers?.get("Content-Type") || "unknown"}`);
|
||||
// Return the file directly (Bun will stream it efficiently)
|
||||
return new Response(file, {
|
||||
|
|
|
|||
Loading…
Reference in New Issue