import { accepts } from "https://esm.town/v/vladimyr/accepts";
export default async function(req: Request): Promise<Response> {
const accept = accepts(req);
const headers = new Headers();
switch (accept.types("json", "html")) {
case "json":
return Response.json({ hello: "world" });
case "html":
headers.set("content-type", "text/html");
return new Response("<b>hello, world!</b>", { headers });
default:
headers.set("content-type", "text/plain");
return new Response("hello, world!", { headers });
}
}