1.1.2Updated a month ago
export const ServeTyped = (path: string, { status, statusText }: { status?: number, statusText?: string } = {}) => {
  const ext = extract_extension.exec(path)?.[1];
  
  let type: string;
  switch(ext) {
    case 'ts':    type = 'application/typescript';  break;
    case 'tsx':   type = 'application/typescript';  break;
    case 'js':    type = 'text/javascript';         break;
    case 'jsx':   type = 'text/javascript';         break;
    case 'json':  type = 'application/json';        break;
    case 'lock':  type = 'application/json';        break;
    case 'md':    type = 'text/markdown';           break;

    default:      type = 'text/plain';
  }

  return new Response(Deno.readFileSync(path), {
    status,
    statusText,
    headers: new Headers({
      'Content-Type': `${type}; charset=utf-8`
    })
  });
};

const extract_extension = /(?:\.([^.]+))?$/;