You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 22, 2024. It is now read-only.
The Python libraries now support the Cloudflare Workers API calls. The following javascript is lifted from [https://cloudflareworkers.com/](https://cloudflareworkers.com/) and slightly modified.
767
+
768
+
```
769
+
$ cat modify-body.js
770
+
addEventListener("fetch", event => {
771
+
event.respondWith(fetchAndModify(event.request));
772
+
});
773
+
774
+
async function fetchAndModify(request) {
775
+
console.log("got a request:", request);
776
+
777
+
// Send the request on to the origin server.
778
+
const response = await fetch(request);
779
+
780
+
// Read response body.
781
+
const text = await response.text();
782
+
783
+
// Modify it.
784
+
const modified = text.replace(
785
+
"<body>",
786
+
"<body style=\"background: #ff0;\">");
787
+
788
+
// Return modified response.
789
+
return new Response(modified, {
790
+
status: response.status,
791
+
statusText: response.statusText,
792
+
headers: response.headers
793
+
});
794
+
}
795
+
$
796
+
```
797
+
798
+
Here's the website with it's simple ```<body>``` statement
799
+
800
+
```
801
+
$ curl -sS https://example.com/ | fgrep '<body'
802
+
<body>
803
+
$
804
+
```
805
+
806
+
Now lets add the script. Looking above, you will see that it's simple action is to modify the ```<body>``` statement and make the background yellow.
0 commit comments