about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAlan Pearce2023-09-13 10:16:53 +0200
committerAlan Pearce2023-09-13 10:17:56 +0200
commitc738123d55b8c9418a76afcbfd4480cc90de0e94 (patch)
tree672ae9fe9deba17462e5cf0d155bcb6055a3d09b
parent37ee14f5472a9bb4688238fb89bd1d9f2658e66d (diff)
downloadhomestead-c738123d55b8c9418a76afcbfd4480cc90de0e94.tar.lz
homestead-c738123d55b8c9418a76afcbfd4480cc90de0e94.tar.zst
homestead-c738123d55b8c9418a76afcbfd4480cc90de0e94.zip
Use bun's builtin mime logic
-rwxr-xr-xbun.lockbbin3084 -> 2002 bytes
-rw-r--r--package.json2
-rw-r--r--src/index.ts11
3 files changed, 3 insertions, 10 deletions
diff --git a/bun.lockb b/bun.lockb
index 2bb84c6..5af2fa2 100755
--- a/bun.lockb
+++ b/bun.lockb
Binary files differdiff --git a/package.json b/package.json
index 7798b26..314e9f9 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,6 @@
   "name": "homestead",
   "module": "src/index.ts",
   "devDependencies": {
-    "@types/mime-types": "^2.1.1",
     "bun-html-live-reload": "^0.1.1",
     "bun-types": "latest"
   },
@@ -11,7 +10,6 @@
   },
   "type": "module",
   "dependencies": {
-    "mime-types": "^2.1.35",
     "toml": "^3.0.0"
   }
 }
diff --git a/src/index.ts b/src/index.ts
index 1616df7..4382aa4 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -2,7 +2,6 @@ import path from "node:path";
 import fs, { Stats } from "node:fs";
 import fsp from "node:fs/promises";
 import { withHtmlLiveReload } from "bun-html-live-reload";
-import mime from "mime-types";
 import type { BunFile } from "bun-types";
 
 import readConfig from "./config";
@@ -105,10 +104,6 @@ function parseIfModifiedSinceHeader(header: string | null): number {
   return header ? new Date(header).getTime() + 999 : 0;
 }
 
-function getMIME(filename: string): string {
-  return mime.contentType(path.extname(filename)) || "text/plain";
-}
-
 export default withHtmlLiveReload({
   fetch: async function (request) {
     const pathname = new URL(request.url).pathname;
@@ -130,7 +125,7 @@ export default withHtmlLiveReload({
         );
         return serveEncodedFile(files.get(file.relPath + ".br"), 200, {
           "content-encoding": "br",
-          "content-type": getMIME(file.filename),
+          "content-type": file.handle.type,
         });
       } else if (
         encodings.includes("zstd") &&
@@ -138,7 +133,7 @@ export default withHtmlLiveReload({
       ) {
         return serveEncodedFile(files.get(file.relPath + ".zst"), 200, {
           "content-encoding": "zstd",
-          "content-type": getMIME(file.filename),
+          "content-type": file.handle.type,
         });
       } else if (
         encodings.includes("gzip") &&
@@ -146,7 +141,7 @@ export default withHtmlLiveReload({
       ) {
         return serveEncodedFile(files.get(file.relPath + ".gz"), 200, {
           "content-encoding": "gzip",
-          "content-type": getMIME(file.filename),
+          "content-type": file.handle.type,
         });
       }
     }