Robots.txt Response
You can use this document to learn how you can return a static response from serverless scripts. Specifically, this document will use robots.txt as an example.
In the following example, the route is: robots.txt
Review the following sample script:
addEventListener("fetch", event => {
event.respondWith(handleRequest(event.request));
});
async function handleRequest() {
const headers = new Headers();
//Set the proper content-type so the browser understands what we're sending back
headers.set("content-type", ["text/html; charset=UTF-8"]);
//Create a response with the robots.txt data we want
return new Response("User-agent: *\nDisallow: /", {
status: "200",
headers
});
}
You can access your script with any of the delivery domains on your account.
Based on the above example, you can access the script with: https://domain.com/robots.txt
Updated 30 days ago