Questions tagged [cloudflare-workers]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
15 votes
2 answers
5k views

Cloudflare Workers - SPA with Vuejs

Hello I have deployed my Vue.js app to Cloudflare workers using the following commands: wrangler generate --site wrangler publish --env dev This is my wrangler.toml: account_id = "xxx" name = "name"...
Marcos Aguayo's user avatar
11 votes
4 answers
4k views

local development with secrets

I am following this guide to get secrets added to my prod environment with cloudflare workers: https://developers.cloudflare.com/workers/platform/environment-variables/#comparing-secrets-and-...
Justin Beckwith's user avatar
10 votes
1 answer
4k views

How to get the current date in a Cloudflare's worker

The usual Date object on Cloudflare's workers, all return 1 jan,1970... What is the proper way to get the current datetime in a workers' code? Thanks, G
wanted's user avatar
  • 369
10 votes
2 answers
6k views

What are cloudflare KV preview_ids and how to get one?

I have a following wrangler.toml. When I would like to use dev or preview (e.g. npx wrangler dev or npx wrangler preview) wrangler asks to add a preview_id to the KV namespaces. Is this an identifier ...
Veksi's user avatar
  • 3,686
9 votes
2 answers
15k views

CloudFlare Workers - Check for Cookie, Add Headers, Set Cookie

I want to dynamically add http-headers via CloudFlare workers ONLY for the first time visitors. For example these headers: Link: </path/to/file.css>; rel=preload; as=style; nopush Link: </...
Vila's user avatar
  • 345
9 votes
1 answer
3k views

ParcelJS does not bundle imported js library

I have a simple NodeJS app (A Cloudflare Worker). In the main typescript file (index.ts) I import the handler module which has this as the first line: const Monitor = import('ping-monitor') ping-...
Mahdi's user avatar
  • 2,168
9 votes
3 answers
6k views

How to use environment variables in CloudFlare Worker in local development environment

I have a CloudFlare Worker where I have environment variables set in the CF Settings..Environment Variables interface. I also have this wrangler.toml In my worker's index.js I have code reading the ...
Matthew Nichols's user avatar
9 votes
1 answer
2k views

Access nested elements in HTMLRewriter - Cloudflare Workers

I have to access a nested element using HTMLRewriter in a Cloudflare worker. Example <div data-code="ABC"> <div class="title">Title</div> <div class=&...
sparkle's user avatar
  • 7,264
8 votes
0 answers
1k views

Error in cloudflare workers : Uncaught (in response) Error: The script will never generate a response

Hi I'm getting the following error in Cloudflare workers A hanging Promise was canceled. This happens when the worker runtime is waiting for a Promise from JavaScript to resolve, but has detected that ...
E.C's user avatar
  • 294
7 votes
1 answer
5k views

What is CPU time and Wall time in the context of Cloudflare Worker request?

If you see the pricing section of Cloudflare Workers here in the free plan they have the following Up to 10ms CPU time per request and in paid plan following Up to 30s wall time per request ...
kaushalyap's user avatar
  • 13.2k
7 votes
4 answers
4k views

Cloudflare Workers Buffer.from()

I am not that familiar with how Buffers and all that work. In node I can do const str = "dasjkiodjsiodjpasiodfjodifjaspiofjsdioajfpasodfjsdioa"; let buff = Buffer.from(str); // <Buffer 64 ...
Dug's user avatar
  • 75
7 votes
3 answers
2k views

Validating Firebase Auth tokens manually

I'm trying to use cloudflare workers to perform authenticated actions. I'm using firebase for authentication and have access to the Access Tokens coming through but since firebase-admin uses nodejs ...
DimlyAware's user avatar
7 votes
1 answer
4k views

How do I query in MongoDB with Cloudflare workers?

I am trying to query mongodb simple findOne in using mongodb. Cloudflare worker is giving 10ms CPU time but during preview/publish throwing error I have tried installing these npm modules npm i ...
Vishvendra Singh's user avatar
7 votes
2 answers
5k views

Next.js - Serverless rendering with Clouflare Workers?

I'm using Next.js v9 and would like to take advantage of Next's serverless deployment option by using my application with Cloudflare Workers. From the Next.js docs, I know that every serverless ...
mrstack999's user avatar
6 votes
1 answer
3k views

How can I make a Cloudflare worker which overwrites a response status code but preserves the rest of the response?

Specifically I am interested in changing all responses with code 403 to code 404, and changing all responses with code 301 to 302. I do not want any other part of the response to change, except the ...
Dhiraj Gupta's user avatar
6 votes
1 answer
2k views

How can I make an asynchronous request (non-blocking) using a Cloudflare Worker

I'm writing a Cloudflare Worker that needs to ping an analytics service after my original request has completed. I don't want it to block the original request, as I don't want latency or a failure of ...
Zack Bloom's user avatar
  • 8,357
5 votes
1 answer
5k views

Cloudflare Worker TypeError: One-time-use body

I'm trying to use a Cloudflare Worker to proxy a POST request to another server. It is throwing a JS exception – by wrapping in a try/catch blog I've established that the error is: TypeError: A ...
Nick's user avatar
  • 839
5 votes
2 answers
4k views

Cloudflare KV namespace doesn't bind

Ran wrangler dev and it doesn't seem to bind Worker KV: ERROR in /src/handler.ts ./src/handler.ts 16:8-17 [tsl] ERROR in /src/handler.ts(16,9) TS2304: Cannot find name 'generalKV'. Here is ...
CacheUseOnly's user avatar
5 votes
3 answers
4k views

How to locally run my cloudflare worker serverless function, during development?

I managed to deploy my first cloudflare worker using serverless framework according to https://serverless.com/framework/docs/providers/cloudflare/guide/ and it is working when I hit the cloud. During ...
tzador's user avatar
  • 2,561
5 votes
1 answer
1k views

Error: write EPIPE when using wrangler dev to run cloudflare worker using itty-router

I am trying to test run a cloudflare worker locally using wrangler dev (although I have the same issue when running npm start), and I keep getting an EPIPE error. The error message and code are below. ...
eyager's user avatar
  • 113
5 votes
1 answer
2k views

AWS api call with aws4fetch package in cloudflare workers?

I'm not able to call AWS Api's using aws4fetch. Could someone giveme an example on how to call S3 putobject using cloudflare workers ?
madruga's user avatar
  • 134
5 votes
1 answer
1k views

CloudFlare worker environment creates separate services with 1 env each, not 1 service with 2 environments

I'm confused about the intended function of Cloudflare's Worker Environments. In the CloudFlare dashboard, a worker has an environment dropdown, which defaults to "Production". I thought ...
Tyler Nielsen's user avatar
5 votes
1 answer
602 views

Instantiate FetchEvent in Jest for a Cloudflare Worker

The TypeScript template repository for Cloudflare Workers has a test for mocking a GET request whereby Request is instantiated to mock the input parameters for handleRequest. However, I've since ...
Luke Carr's user avatar
  • 561
5 votes
1 answer
1k views

Send an image to Telegram with Cloudflare Workers

I trying to send an image to Telegram with Cloudflare Workers, but I don’t receive the image in my Telegram account. Also my code correctly work in Chrome developer console, so a problem is in ...
Max's user avatar
  • 51
5 votes
1 answer
1k views

"Uncaught TypeError: globalThis.XMLHttpRequest is not a constructor" When publishing cloudflare worker

When i run "wrangler dev", it compiles, tries to upload then gives me this error. A similar error arises when using "warngler dev". Uncaught TypeError: globalThis.XMLHttpRequest ...
Olivia's user avatar
  • 83
5 votes
0 answers
548 views

Resizing images in a Cloudflare Worker with Denoflare and Wasm Photon

I'm trying to learn how to resize images myself in a Cloudflare Worker rather than use Cloudflare Images or Cloudflare Image Resizing (because of pricing). There is an example using Dinoflare with ...
Suragch's user avatar
  • 499k
5 votes
1 answer
5k views

Getting error 10021 when uploading cloudflare worker

I'm trying to write a cloudflare worker following the documentation and use Webpack to generate one single file to upload. After running the script as in the docs: curl -X PUT "https://api....
martosoler's user avatar
4 votes
2 answers
5k views

How to verify Stripe's webhook signature?

I have figured out the problem thanks to the extensive answer from @user9014097. This section in particular describes my mistake/oversight: The formatting of the message plays a role in determining ...
J. van Mourik's user avatar
4 votes
1 answer
762 views

Should I commit my wrangler.toml file with KV namespace values present?

I've created an API using Cloudflare Workers and it uses their KV service. The KV namespaces are defined in the wrangler.toml file but I'm unsure if it is safe to commit that file with the ...
Stephen Gilboy's user avatar
4 votes
1 answer
1k views

CloudFlare workers fetch HTTPS works on workers.dev subdomain but not on own subdomain getting 525 error

I have a simple worker that just does a fetch against an HTTPS endpoint somewhere else. The code is literally just: return await fetch('https://something.com/someResource') When I test locally (...
Killerpixler's user avatar
  • 4,298
4 votes
1 answer
1k views

Accessing Compressed Data for Cloudflare Workers Sites

My cloudflare workers site houses binary data that a react app fetches. This binary data is stored as gzip compressed as it compresses extremely well (we're talking about a 20-25x reduction and ...
Nick Babcock's user avatar
  • 6,121
4 votes
1 answer
559 views

Extracting innerHTML of Element from Web Page via CloudFlare Worker

I am trying to extract the full innerHTML of particular element via a CloudFlare worker. I tried using their HTMLRewriter but that appears to be more of a stream API. It also doesn't appear to be able ...
ChaseLouisPowers's user avatar
4 votes
1 answer
8k views

How to fix authentication error code 10000 in cloudflare

There is problem, i keep encountering in cloudflare. It says - authentication error (code 10000) while logging to my cloudflare dashbord. don't know why that's happen,but i searched for that problem ...
Degital Abhishek's user avatar
3 votes
3 answers
7k views

environment variable use in Cloudflare workers node.js

I saw many articles setting environment variables in Cloudflare workers. but I am not able to read or retrieve it in node.js Code: async function handleRequest(request) { if ('OKOK' == process.env....
Noobdeveloper's user avatar
3 votes
2 answers
3k views

Cache-Control headers in a Cloudflare Workers site

I'm just testing Workers sites with a Hugo-created static site. It already existed, so I used the docs’ instructions for adapting an existing site. The cache-control headers for the woff2 and css ...
Bryce Wray's user avatar
3 votes
1 answer
3k views

Using environment variables in Typescript

Is there a proper way to include environment variables in a .ts file? They are declared in wrangler.toml or through the CLI, but Typescript won't know they are there. Currently I either use a .js file ...
David Min's user avatar
  • 1,346
3 votes
1 answer
4k views

Set more than one cookie in the 'Set-Cookie' header in a cloudflare worker header.set('Set-Cookie' function

I'm trying to use a cloudfare worker to add 2 cookie key/value pairs to the response before sending it to the client. Unfortunately all documentation for the cloudflare workers says to use the ...
Michael's user avatar
  • 155
3 votes
1 answer
3k views

How to inject javascript in existing HTML response with node.js and cloudflare workers

I have a vanity URL pointing to a GitBook. GitBook doesn't support the insertion of arbitrary javascript snippets. At the moment GitBook has 4 "integrations" only. I could route through my own VM ...
Kind Contributor's user avatar
3 votes
2 answers
1k views

Sveltekit development with workers KV -- hot reloading

Is it possible to use CloudFlare's Workers KV when developing a Svelte/kit application? It is possible to build the app then run wrangler dev when using the CloudFlare Workers adapter: npm build ...
Nick's user avatar
  • 5,884
3 votes
2 answers
3k views

cloudflare worker rewrite Host Header

How do I set up another Host Header in the cloudflare worker? For example, I have set up a 1.2.3.4 ip for my site's www record By default www requests are sent with the header www.ex.com but I want to ...
javad's user avatar
  • 41
3 votes
1 answer
2k views

How to ensure a Sveltekit project can actually run on Cloudflare workers?

Sveltekit and Cloudflare seem to be a great match. My objective is to deliver well-tested code, that runs smoothly on Cloudflare pages/workers. To do this, I use Cypress.io for e2e testing. The ...
DauleDK's user avatar
  • 3,285
3 votes
1 answer
1k views

How to put breakpoints and debug Cloudflare Workers?

How do I put breakpoints and debug Cloudflare Workers? I've read the Cloudflare "Debugging Workers" guide, and unfortunately, it is not helpful. It does mention: Inserting console.log lines ...
Ben Butterworth's user avatar
3 votes
2 answers
2k views

How do you use ES6 exports in Cloudflare worker scripts?

I'm trying to get familiar with CloudFlare workers. I've copied a quickstart project from https://developers.cloudflare.com/workers/get-started/quickstarts, via: wrangler generate my-app https://...
Wintermute's user avatar
  • 3,015
3 votes
1 answer
2k views

Inject HTML with Cloudflare worker

I'm trying to use HTMLRewriter to inject a preload <link> into web pages on my site, but nothing is happening. The code I am using is: addEventListener("fetch", (event) => { event....
Derek Johnson's user avatar
3 votes
2 answers
473 views

Possible to A/B test between two targets under one CNAME?

Is it possible to dynamically route between two targets under one CNAME? I couldn't find any specific documentation where Cloudflare workers or page rules could accomplish this. For context my team ...
bteng22's user avatar
  • 61
3 votes
1 answer
2k views

Trouble with Cloudflares Worker Cache API

I’ve now spent countless hours trying to get the cache API to cache a simple request. I had it working once in between but forgot to add something to the cache key, and now its not working anymore. ...
user13737110's user avatar
3 votes
1 answer
2k views

How do I use environment variables in a SvelteKit app hosted on Cloudflare Pages?

I am making a site for a very small organisation I am involved in, and have been asked to design it in a way where hosting costs virtually nothing. I have opted to use SvelteKit (hosted on Cloudflare ...
lia07's user avatar
  • 119
3 votes
2 answers
832 views

Hanging promise canceled

I'm trying to set Cloudflare's workers to track the circulation of some ERC20 tokens as an exercise to learn web3 and wasm. Thought it could be simple enough, but about 90% of the time so far has been ...
Corfucinas's user avatar
3 votes
2 answers
2k views

NuxtJs SSR deployment on Cloudflare Workers

I'm working on a Nuxt project and would like to deploy it on Cloudflare Workers with its SSR feature, not a static site. I could find a solution for static site deployment below. wrangler init --site ...
Vitalii Kuzin's user avatar
3 votes
1 answer
91 views

Error trying to zero-copy deserialize using serde in Cloudflare workers

I have a struct containing &str with the same lifetime annotation as the struct itself. When I try to call the first::<T>(None) method on a worker::d1::D1PreparedStatement, which is supposed ...
Lu_'s user avatar
  • 31

1
2 3 4 5
8