cloudflare-workers

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

不羁的心 提交于 2021-01-27 17:22:39
问题 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 response.headers.set('Set-Cookie',xxx) function to set the cookie value: let response = await fetch(request); response = new Response(response.body, response); response.headers.set('Set-Cookie', "val1=x; Expires=Wed, 21 Oct 2020 07:28:00 GMT; Path='/';"); return response; This only allows you to set one

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

夙愿已清 提交于 2020-01-13 06:36:47
问题 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 server to accomplish this, but I have CloudFlare and I want to try out workers. (Javascript running at the CDN edge). The CloudFlare worker environment makes header injection very easy, but there is no obvious way to do this. 回答1: It's important to process with a TransformStream so that processing is

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

有些话、适合烂在心里 提交于 2019-12-11 04:37:47
问题 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 development, would like to be able to test on http://localhost:8080/* What is the simplest way to bring up a local http server and handle my requests using function specified in serverless.yml? I looked into https://github.com/serverless/examples/tree/master/google-node-simple-http-endpoint but

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

。_饼干妹妹 提交于 2019-12-10 14:19:36
问题 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 requests. How can I create a request which starts and ends after the original request completes? addEventListener('fetch', event => { event.respondWith(handle(event)) }) async function handle(event) { const response = await fetch(event.request) // Send