{"id":13726922,"url":"https://github.com/worker-tools/deno-fetch-event-adapter","last_synced_at":"2025-04-14T14:53:23.227Z","repository":{"id":37846627,"uuid":"347885685","full_name":"worker-tools/deno-fetch-event-adapter","owner":"worker-tools","description":"Dispatches global fetch events using Deno's native http server.","archived":false,"fork":false,"pushed_at":"2022-05-27T11:10:04.000Z","size":116,"stargazers_count":22,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-09T04:04:11.233Z","etag":null,"topics":["cloudflare-workers","deno","fetch-event","polyfill","service-worker"],"latest_commit_sha":null,"homepage":"https://workers.tools/deno-fetch-event-adapter","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/worker-tools.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-03-15T08:09:56.000Z","updated_at":"2025-04-03T22:14:17.000Z","dependencies_parsed_at":"2022-08-19T07:41:18.843Z","dependency_job_id":null,"html_url":"https://github.com/worker-tools/deno-fetch-event-adapter","commit_stats":null,"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/worker-tools%2Fdeno-fetch-event-adapter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/worker-tools%2Fdeno-fetch-event-adapter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/worker-tools%2Fdeno-fetch-event-adapter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/worker-tools%2Fdeno-fetch-event-adapter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/worker-tools","download_url":"https://codeload.github.com/worker-tools/deno-fetch-event-adapter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248901195,"owners_count":21180368,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloudflare-workers","deno","fetch-event","polyfill","service-worker"],"created_at":"2024-08-03T01:03:31.557Z","updated_at":"2025-04-14T14:53:23.208Z","avatar_url":"https://github.com/worker-tools.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# Deno Fetch Event Adapter\n\nDispatches global `fetch` events using Deno's [native HTTP server](https://deno.com/blog/v1.9#native-http%2F2-web-server).\n\n~~It is mostly intended as a temporary solution until Deno [implements the Service Worker spec](https://github.com/denoland/deno/issues/5957#issuecomment-722568905) directly.~~   \nThis has been scrapped, but this module works just fine for local testing, developing Cloudflare Workers while offline, and similar use cases.\n\n## Example\n\n```ts\n// file: \"worker.js\"\nimport 'https://deno.land/x/fetch_event_adapter/listen.ts';\n\n// This module adds a global `FetchEvent`\nif (typeof FetchEvent !== 'undefined') console.log(true);\n\n// This module also adds global type declarations, s.t. this type-checks:\nself.addEventListener('fetch', event =\u003e {\n  const ip = event.request.headers.get('x-forwarded-for');\n  event.respondWith(new Response(`Hello ${ip ?? 'World'}`));\n});\n```\n\nYour script needs the `--allow-net` permissions. It also requires a `--location`,\nto know on which port to listen for incoming connections:\n\n```sh\ndeno run --allow-net --location=http://localhost:8000 worker.js\n```\n\nIf you set the `--location` to either HTTPS or port 443, you have to provide a `--cert` and a `--key` parameter.\nYour script will also need the read permission to read the files:\n\n```sh\ndeno run --allow-net --allow-read --location=https://localhost:8000 worker.js \\\n  --cert=./path/to/cert.pem \\\n  --key=./path/to/key.pem\n```\n\n## Error Handling\nIf an error occurs during estabslishing a connection (e.g. invalid certificate, etc...), the error is dispatched as a global `error` event rather then crashing the process. You can add custom logging like this:\n\n```ts\nself.addEventListener('error', event =\u003e {\n  console.warn(event.message);\n  console.warn(event.error);\n});\n```\n\n--------\n\n\u003cp align=\"center\"\u003e\u003ca href=\"https://workers.tools\"\u003e\u003cimg src=\"https://workers.tools/assets/img/logo.svg\" width=\"100\" height=\"100\" /\u003e\u003c/a\u003e\n\u003cp align=\"center\"\u003eThis module is part of the Worker Tools collection\u003cbr/\u003e⁕\n\n[Worker Tools](https://workers.tools) are a collection of TypeScript libraries for writing web servers in [Worker Runtimes](https://workers.js.org) such as Cloudflare Workers, Deno Deploy and Service Workers in the browser. \n\nIf you liked this module, you might also like:\n\n- 🧭 [__Worker Router__][router] --- Complete routing solution that works across CF Workers, Deno and Service Workers\n- 🔋 [__Worker Middleware__][middleware] --- A suite of standalone HTTP server-side middleware with TypeScript support\n- 📄 [__Worker HTML__][html] --- HTML templating and streaming response library\n- 📦 [__Storage Area__][kv-storage] --- Key-value store abstraction across [Cloudflare KV][cloudflare-kv-storage], [Deno][deno-kv-storage] and browsers.\n- 🆗 [__Response Creators__][response-creators] --- Factory functions for responses with pre-filled status and status text\n- 🎏 [__Stream Response__][stream-response] --- Use async generators to build streaming responses for SSE, etc...\n- 🥏 [__JSON Fetch__][json-fetch] --- Drop-in replacements for Fetch API classes with first class support for JSON.\n- 🦑 [__JSON Stream__][json-stream] --- Streaming JSON parser/stingifier with first class support for web streams.\n\nWorker Tools also includes a number of polyfills that help bridge the gap between Worker Runtimes:\n- ✏️ [__HTML Rewriter__][html-rewriter] --- Cloudflare's HTML Rewriter for use in Deno, browsers, etc...\n- 📍 [__Location Polyfill__][location-polyfill] --- A `Location` polyfill for Cloudflare Workers.\n- 🦕 [__Deno Fetch Event Adapter__][deno-fetch-event-adapter] --- Dispatches global `fetch` events using Deno’s native HTTP server.\n\n[router]: https://workers.tools/router\n[middleware]: https://workers.tools/middleware\n[html]: https://workers.tools/html\n[kv-storage]: https://workers.tools/kv-storage\n[cloudflare-kv-storage]: https://workers.tools/cloudflare-kv-storage\n[deno-kv-storage]: https://workers.tools/deno-kv-storage\n[kv-storage-polyfill]: https://workers.tools/kv-storage-polyfill\n[response-creators]: https://workers.tools/response-creators\n[stream-response]: https://workers.tools/stream-response\n[json-fetch]: https://workers.tools/json-fetch\n[json-stream]: https://workers.tools/json-stream\n[request-cookie-store]: https://workers.tools/request-cookie-store\n[extendable-promise]: https://workers.tools/extendable-promise\n[html-rewriter]: https://workers.tools/html-rewriter\n[location-polyfill]: https://workers.tools/location-polyfill\n[deno-fetch-event-adapter]: https://workers.tools/deno-fetch-event-adapter\n\nFore more visit [workers.tools](https://workers.tools).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fworker-tools%2Fdeno-fetch-event-adapter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fworker-tools%2Fdeno-fetch-event-adapter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fworker-tools%2Fdeno-fetch-event-adapter/lists"}