Created
January 11, 2024 20:19
-
-
Save zootella/5c5252f920e6f66826452d959eacd08b to your computer and use it in GitHub Desktop.
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
/* | |
2024jan11 demo: | |
-all local | |
-pages:dev | |
-react and vue | |
-console.log client and server | |
$ npm create cloudflare@latest | |
localr, React, all default or no | |
localv, Vue, all default or no | |
drop in ./functions/api.js: | |
*/ | |
export function onRequest(context) {//we're given a context object about the incoming request | |
let version = "Version 2024jan11a"; | |
let i = context.request.headers.entries(); | |
let o = {}; | |
let duplicate = false; | |
for (const [k, v] of i) { | |
if (!o[k]) | |
o[k] = v; | |
else | |
duplicate = true; | |
} | |
let o2 = {}; | |
o2.requestContext = context; | |
o2.message = "Hello from this cold2.cc cloudflare pages function!"; | |
o2.secretLength = (context.env.MY_FIRST_SECRET) ? context.env.MY_FIRST_SECRET.length : 0; | |
o2.version = version; | |
o2.serverTick = Date.now(); | |
o2.headers = o; | |
o2.headersDuplicate = duplicate; | |
console.log("hello from server side code, " + version); | |
return Response.json(o2); | |
} | |
/* | |
$ npm run pages:dev | |
localr "[wrangler] Could not proxy request: TypeError: fetch failed" | |
localv works | |
*/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment