Skip to content

Instantly share code, notes, and snippets.

@jasonbyrne
Created April 27, 2020 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonbyrne/6740151c59978ce205121ddef540bcb2 to your computer and use it in GitHub Desktop.
Save jasonbyrne/6740151c59978ce205121ddef540bcb2 to your computer and use it in GitHub Desktop.
Modify the body at edge with Cloudflare and StackPAth
export async function personalizeBody(
response: Response,
request: Request
): Promise<Response> {
const originalBody = await response.text();
const newBody = originalBody.replace(
/{{ timestamp }}/g,
new Date().toUTCString()
);
const modifiedResponse = new Response(newBody, response);
modifiedResponse.headers.set("Content-Length", String(newBody.length));
return modifiedResponse;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment