- bunny.net to the contents of the <title> tag, so every page carries it.
import * as BunnySDK from "@bunny.net/edgescript-sdk";
/**
* When a response is not served from the cache, you can use this event handler
* to modify the response coming from the origin. This runs before the response
* is cached.
*
* Returns an HTTP response.
* @param {Context} context - The context of the middleware.
* @param {Request} request - The current request done to the origin.
* @param {Response} response - The HTTP response or string.
*/
async function onOriginResponse(context: {
request: Request;
response: Response;
}): Promise<Response> | Response | void {
let body = await context.response.text();
body = body.replace("</title>", "- bunny.net</title>");
// Remove the original Content headers so the response is returned correctly
const headers = new Headers(context.response.headers);
headers.delete("Content-Length");
headers.delete("Content-Encoding");
return new Response(body, {
status: context.response.status, // Preserve the original status code
headers, // Preserve the original headers
});
}
BunnySDK.net.http.servePullZone().onOriginResponse(onOriginResponse);