const robotsTxtContent = "User-agent: BadBot\nDisallow: /\n";
addEventListener("fetch", (event) =>
event.respondWith(handleRequest(event.request))
);
async function handleRequest(req) {
const url = new URL(req.url);
if (url.pathname === "/robots.txt") {
return new Response(robotsTxtContent, {
status: 200,
headers: new Headers({
"content-type": "text/plain"
})
});
}
return new Response("Not found", { status: 404 });
}