Questions tagged [cloudflare-workers]
373 questions
15
votes
2 answers
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"
type = "webpack"
workers_dev =…

Marcos Aguayo
- 6,840
- 8
- 28
- 61
10
votes
2 answers
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 to an existing KV namespace?
I see there is a…

Veksi
- 3,556
- 3
- 30
- 69
9
votes
4 answers
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-environment-variables
I am able to add new secrets via…

Justin Beckwith
- 7,686
- 1
- 33
- 55
9
votes
1 answer
Access nested elements in HTMLRewriter - Cloudflare Workers
I have to access a nested element using HTMLRewriter in a Cloudflare worker.
Example
I…
Title
9,99
Title

sparkle
- 7,530
- 22
- 69
- 131
9
votes
2 answers
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 variable REGISTRATION_API_URL. If the code is…

Matthew Nichols
- 4,866
- 4
- 41
- 48
9
votes
1 answer
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
- 358
- 3
- 12
9
votes
2 answers
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: ; rel=preload; as=style; nopush
Link: ; rel=preload; as=script; nopush
So, what…

Vila
- 345
- 2
- 5
- 12
7
votes
3 answers
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 modules it can't work on the platform so i'm left…

DimlyAware
- 433
- 2
- 4
- 17
7
votes
4 answers
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); //

Dug
- 75
- 1
- 4
7
votes
1 answer
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
Typically it takes more time than 10ms to execute a…

user158
- 12,852
- 7
- 62
- 94
7
votes
2 answers
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 function created by Next has the following…

mrstack999
- 307
- 3
- 11
7
votes
1 answer
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 mongodb, mongodb-core, dgram, fs
var MongoClient =…

Vishvendra Singh
- 484
- 5
- 19
6
votes
0 answers
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 the Promise cannot possibly ever resolve because…

E.C
- 254
- 3
- 6
6
votes
1 answer
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 status text (which I want to be empty). Below is my…

Dhiraj Gupta
- 63
- 1
- 4
6
votes
1 answer
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 the analytics system to slow down or break…

Zack Bloom
- 8,309
- 2
- 20
- 27