Created
April 27, 2020 13:35
-
-
Save jasonbyrne/6740151c59978ce205121ddef540bcb2 to your computer and use it in GitHub Desktop.
Modify the body at edge with Cloudflare and StackPAth
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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