Skip to content
Permalink
Browse files

initial

  • Loading branch information...
thomasfr committed Jul 16, 2019
0 parents commit 94c0ecda4f712a37e65ec1de9bd2b8a6d700087f
Showing with 475 additions and 0 deletions.
  1. +9 −0 .gitignore
  2. +20 −0 index.js
  3. +29 −0 package.json
  4. +6 −0 wrangler.toml
  5. +411 −0 yarn.lock
@@ -0,0 +1,9 @@
/target
**/*.rs.bk
Cargo.lock
bin/
pkg/
wasm-pack.log
worker/
node_modules/
.cargo-ok
@@ -0,0 +1,20 @@
/**
* Adds a listener for the 'fetch' event
* @see https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API/Using_Service_Workers#Custom_responses_to_requests
* @param {String} event name
* @param {FetchEvent} event
*/
addEventListener("fetch", async event => {
event.respondWith(handleRequest(event.request));
});

/**
* Makes the requests as is and adds a 'X-CF-Worker' http header with the name of this worker to the response
* @param {Request} request
*/
async function handleRequest(request) {
let response = await fetch(request); // executes the actual original request as is without modifying it in any way
response = new Response(response.body, response);
response.headers.append("X-CF-Worker", "<NAME OF THIS WORKER HERE>"); // add a custom Header indicating that this was intercepted by our Worker for debugging)
return response;
}
@@ -0,0 +1,29 @@
{
"name": "worker-template",
"version": "1.0.0",
"description": "Template for generating a cloudflare worker with wrangler",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"format": "prettier --write '**/*.{js,css,json,md}'"
},
"author": "Thomas Fritz <thomas.fritz@eversports.com>",
"devDependencies": {
"husky": "^2.1.0",
"prettier": "^1.17.0"
},
"husky": {
"hooks": {
"pre-commit": "npm run format",
"pre-push": "npm run format"
}
},
"dependencies": {
"serverless-cloudflare-workers": "^1.2.0"
},
"eslintConfig": {
"env": {
"worker": true
}
}
}
@@ -0,0 +1,6 @@
name = "worker-template"
type = "webpack"
private = false
account_id = "fdd540d48b115ab59642c845313ff17f"
zone_id = "<YOUR ZONE ID>" # find the Zone ID on the 'Overview' page on Cloudflare
route = "example.eversports.<tld>/foo/*"

0 comments on commit 94c0ecd

Please sign in to comment.
You can’t perform that action at this time.