export async function onRequest(context) {
const myVar = constext.env.[your-envirment-variable];
console.log("myvar = '${myVar}'");
// Note: I'm not sure the console will return value because of security settings. So you might need to do some trick to get pass that. So it might seem like nothing is returned if your logging it out. But if you combine it into an other object it should get around it so you can see it in the logs.
}[vars]
myVar = "somthing"wrangler or a framework's dev command. If you need bindings support, you either need to build your project then run wrangler pages dev on the output, or use something like cf-bindings-proxynpm i cf-bindings-proxy. There are no other projects in the npm registry using cf-bindings-proxy.
request.clone() or response.clone()platform.env in sveltekit? I've spend too much time in development setupENVIRONMENT in my api endpoint's +server.ts, im so stuckResponse will be different between the two, and any code placed outside of functions will use that tsconfig. So my question is, where do people put things like helpers/utils for functions specific things and not have them exposed as routes?import consumers from 'stream/consumers', miniflare complains:Buffer and Streams API are supported, and I have set node_compat = true in my wrangler.toml. import consumers from 'node:stream/consumers' instead btw.)compatibility_flags = [ "nodejs_compat" ] in addition to node_compat = true?
wrangler 's live reload function seems to break with these nodejs_compat imports. So what I'm seeing is that I can get the code to compile fine when I first run wrangler dev but if I make any code changes at all and wrangler does a live reload, it'll throw that error.nodejs_compat compat flag, not node_compat to import from any node: namespace. But yes, the latest version of wrangler did break live reloads with node: imports, and is being tracked here: https://github.com/cloudflare/workers-sdk/issues/4959nodejs_compat and node_compat flags?node_compat is old and polyfills a bunch of stuff. It's not great, a bit slow, adds to bundle size, and the polyfills aren't perfect. nodejs_compat is Cloudflare's actual Node.js compatibility built right into the workerd runtime. There's some DX pain aroound them both existing right now which I wrote up a bit at https://github.com/cloudflare/workers-sdk/issues/4082nodejs_compat these days, unless you're using something legacy that specifically needs node_compat, like pgexport async function onRequest(context) {
const myVar = constext.env.[your-envirment-variable];
console.log("myvar = '${myVar}'");
// Note: I'm not sure the console will return value because of security settings. So you might need to do some trick to get pass that. So it might seem like nothing is returned if your logging it out. But if you combine it into an other object it should get around it so you can see it in the logs.
}✨ Compiled Worker successfully
⛅️ wrangler 3.26.0
-------------------
Your worker has access to the following bindings:
- D1 Databases:
- DB: local-DB (DB)
⎔ Starting local server...
[wrangler:inf] Ready on http://localhost:8080
X [ERROR] Your worker created multiple branches of a single stream (for instance, by calling `response.clone()` or `request.clone()`) but did not read the body of both branches. This is wasteful, as it forces the system to buffer the entire stream of data in memory, rather than streaming it through. This may cause your worker to be unexpectedly terminated for going over the memory limit. If you only meant to copy the request or response headers and metadata (e.g. in order to be able to modify them), use the appropriate constructors instead (for instance, `new Response(response.body, response)`, `new Request(request)`, etc).
[wrangler:inf] POST /api/v1/waitlist 200 OK (6ms)export async function onRequest(ctx: EventContext) {
const response = await ctx.next();
logRequest(ctx.env.DB, ctx.request);
return response;
};import EventContext from "@/types/EventContext";
export async function onRequestGet(ctx: EventContext) {
console.log("test_get");
return Response.json({
"get": 404,
});
}
export async function onRequestPost(ctx: EventContext) {
console.log("test_post");
return Response.json({
"post": 404,
});
}export async function onRequest(context){
console.log('Hello');
return await next();
}✘ [ERROR] Could not resolve "stream/consumers"
src/routes/headlines.ts:13:22:
13 │ import consumers from 'stream/consumers'
╵ ~~~~~~~~~~~~~~~~~~
The package "stream/consumers" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.