the implementation seems to be to use Turnstile? Is that what it is supposed to be or am I going dow
the implementation seems to be to use Turnstile? Is that what it is supposed to be or am I going down the wrong path?
pub.dev, so you would have to do it yourselfAuthorization header, you can reject requests without it in the WAF rather than your Worker and then your Worker would never be invoked for those requests.global.js, containing a {}, which multiple scripts import and hook things onto, will this leak/bleed into multiple requests to my worker given Node's import caching, or will it be isolated to just the current request?foo=1, and I want to hook that onto a global object so other files can use it, rather than laboriously having to pass it around to all functions. But the next request may send QS foo=2. Sounds like I'll be OK based on what you say. (But presumably in a non-serverless/Worker environment this would be problematic?)
globalObject.localStorage wouldn't work? If so, using AsyncLocalStorage, am I right that it would look something like this, to store a global property for later reading downstream?run takes the object you want to store, and then a callback // Fetch the resource using childWorker1
const childWorker1Response = await env.childWorker1.fetch(request.clone());
// Fully consume the response body of childWorker1
const childWorker1ResponseBody = await childWorker1Response.text();
// Fetch a resource using childWorker2, passing the response body of childWorker1 as the POST body
const childWorker2Response = await env.childWorker2.fetch(request.clone(), {
method: 'POST',
body: childWorker1ResponseBody
});globalObject.localStorageimport { AsyncLocalStorage } from 'node:async_hooks';
const fooStore = new AsyncLocalStorage();
fooStore.run('bar'); //<-- running in some async middlewareimport { AsyncLocalStorage } from 'node:async_hooks';
const fooStore = new AsyncLocalStorage();
const fooVal = fooStore.getStore(); //"bar"import { AsyncLocalStorage } from "node:async_hooks";
const asyncLocalStorage = new AsyncLocalStorage();
async function doStuff() {
const { req, env, ctx } = asyncLocalStorage.getStore();
const obj = await env.KV.get("foo");
// ...
}
export default {
async fetch(req, env, ctx) {
return asyncLocalStorage.run({ req, env, ctx }, async () => {
await doStuff();
return new Response("Hello World!");
});
},
};