file server content type headers
This commit is contained in:
@@ -6,6 +6,7 @@ import type {
|
||||
RouteConfigurator,
|
||||
RouterContext,
|
||||
} from "./types.ts";
|
||||
import { getContentTypeByExtension } from "./util/contentType.ts";
|
||||
import { NotFound } from "./util/response.ts";
|
||||
|
||||
/**
|
||||
@@ -392,7 +393,9 @@ export class Router {
|
||||
|
||||
try {
|
||||
const file = await Deno.readFile(normalizedPath);
|
||||
return new Response(file);
|
||||
const filetype = normalizedPath.split(".")[1];
|
||||
const contentType = getContentTypeByExtension(filetype);
|
||||
return new Response(file, { headers: { "Content-Type": contentType } });
|
||||
} catch (e) {
|
||||
if (e instanceof Deno.errors.NotFound) {
|
||||
return showIndex ? generateIndex(normalizedPath) : NotFound();
|
||||
|
Reference in New Issue
Block a user