From 1d3be789172c68ecb448e6d52a324a4e71896865 Mon Sep 17 00:00:00 2001 From: Emma Date: Tue, 21 Jan 2025 01:23:41 -0700 Subject: [PATCH] improved content types --- deno.json | 2 +- router.ts | 2 +- util/contentType.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/deno.json b/deno.json index 3f80445..0d05c50 100755 --- a/deno.json +++ b/deno.json @@ -1,7 +1,7 @@ { "name": "@bearmetal/router", "description": "A simple router for Deno", - "version": "0.2.4", + "version": "0.2.5", "stable": true, "files": [ "mod.ts", diff --git a/router.ts b/router.ts index af68a23..8f2eb04 100755 --- a/router.ts +++ b/router.ts @@ -393,7 +393,7 @@ export class Router { try { const file = await Deno.readFile(normalizedPath); - const filetype = normalizedPath.split(".")[1]; + const filetype = normalizedPath.split(".").at(-1); const contentType = getContentTypeByExtension(filetype); return new Response(file, { headers: { "Content-Type": contentType } }); } catch (e) { diff --git a/util/contentType.ts b/util/contentType.ts index 645dd88..e517de8 100755 --- a/util/contentType.ts +++ b/util/contentType.ts @@ -1,4 +1,4 @@ -export function getContentTypeByExtension(extension: string) { +export function getContentTypeByExtension(extension?: string) { switch (extension) { case "html": case "htm":