All Projects → worker-tools → deno-fetch-event-adapter

worker-tools / deno-fetch-event-adapter

Licence: MIT license
Dispatches global fetch events using Deno's native http server.

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to deno-fetch-event-adapter

edge-mock
Tools for testing and developing CloudFlare worker apps.
Stars: ✭ 49 (+172.22%)
Mutual labels:  service-worker, cloudflare-workers
html
HTML templating and streaming response library for Service Worker-like environments such as Cloudflare Workers.
Stars: ✭ 41 (+127.78%)
Mutual labels:  service-worker, cloudflare-workers
parsed-html-rewriter
A DOM-based implementation of Cloudflare Worker's HTMLRewriter.
Stars: ✭ 34 (+88.89%)
Mutual labels:  polyfill, cloudflare-workers
deno-csv
Streaming API for reading and writing CSV for https://deno.land/
Stars: ✭ 34 (+88.89%)
Mutual labels:  deno
dem
A module version manager for Deno.
Stars: ✭ 58 (+222.22%)
Mutual labels:  deno
offline-first-sw
Service worker example with 404 handling, custom offline page and max TTL for specific file types.
Stars: ✭ 82 (+355.56%)
Mutual labels:  service-worker
deno install
Deno 安装器(国内加速)
Stars: ✭ 58 (+222.22%)
Mutual labels:  deno
array-includes
Array.prototype.includes spec-compliant polyfill
Stars: ✭ 42 (+133.33%)
Mutual labels:  polyfill
ember-on-modifier
Implements the `{{on eventName this.someAction}}` element modifier from https://github.com/emberjs/rfcs/blob/master/text/0471-on-modifier.md
Stars: ✭ 37 (+105.56%)
Mutual labels:  polyfill
seamless-scroll-polyfill
Scroll Behavior polyfill
Stars: ✭ 134 (+644.44%)
Mutual labels:  polyfill
deno-drash-realworld-example-app
Deno + Drash RealWorld example app
Stars: ✭ 56 (+211.11%)
Mutual labels:  deno
iam-policies
Iam policies implementation for create roles and manage permissions
Stars: ✭ 20 (+11.11%)
Mutual labels:  deno
sanitizer-polyfill
rewrite constructor arguments, call DOMPurify, profit
Stars: ✭ 46 (+155.56%)
Mutual labels:  polyfill
hex
An ecosystem delivering practices, philosophy and portability. Powered By Deno and JavaScript.
Stars: ✭ 48 (+166.67%)
Mutual labels:  deno
i18next-http-backend
i18next-http-backend is a backend layer for i18next using in Node.js, in the browser and for Deno.
Stars: ✭ 270 (+1400%)
Mutual labels:  deno
react-mobx-antd-boilerplate
react16-router4--mobx-antd3--webpack4-boilerplate
Stars: ✭ 15 (-16.67%)
Mutual labels:  service-worker
String.prototype.trim
ES5 spec-compliant shim for String.prototype.trim
Stars: ✭ 13 (-27.78%)
Mutual labels:  polyfill
logrocket deno api
A functional CRUD-like API with Deno and Postgres
Stars: ✭ 23 (+27.78%)
Mutual labels:  deno
rippledb
Embeddable key-value database engine in pure TypeScript, based on LSM-Tree
Stars: ✭ 33 (+83.33%)
Mutual labels:  deno
crafthead
Super scalable Minecraft avatar generation, built on Cloudflare Workers
Stars: ✭ 67 (+272.22%)
Mutual labels:  cloudflare-workers

Deno Fetch Event Adapter

Dispatches global fetch events using Deno's native HTTP server.

It is mostly intended as a temporary solution until Deno implements the Service Worker spec directly.
This has been scrapped, but this module works just fine for local testing, developing Cloudflare Workers while offline, and similar use cases.

Example

// file: "worker.js"
import 'https://deno.land/x/fetch_event_adapter/listen.ts';

// This module adds a global `FetchEvent`
if (typeof FetchEvent !== 'undefined') console.log(true);

// This module also adds global type declarations, s.t. this type-checks:
self.addEventListener('fetch', event => {
  const ip = event.request.headers.get('x-forwarded-for');
  event.respondWith(new Response(`Hello ${ip ?? 'World'}`));
});

Your script needs the --allow-net permissions. It also requires a --location, to know on which port to listen for incoming connections:

deno run --allow-net --location=http://localhost:8000 worker.js

If you set the --location to either HTTPS or port 443, you have to provide a --cert and a --key parameter. Your script will also need the read permission to read the files:

deno run --allow-net --allow-read --location=https://localhost:8000 worker.js \
  --cert=./path/to/cert.pem \
  --key=./path/to/key.pem

Error Handling

If 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:

self.addEventListener('error', event => {
  console.warn(event.message);
  console.warn(event.error);
});

This module is part of the Worker Tools collection

Worker Tools are a collection of TypeScript libraries for writing web servers in Worker Runtimes such as Cloudflare Workers, Deno Deploy and Service Workers in the browser.

If you liked this module, you might also like:

  • 🧭 Worker Router --- Complete routing solution that works across CF Workers, Deno and Service Workers
  • 🔋 Worker Middleware --- A suite of standalone HTTP server-side middleware with TypeScript support
  • 📄 Worker HTML --- HTML templating and streaming response library
  • 📦 Storage Area --- Key-value store abstraction across Cloudflare KV, Deno and browsers.
  • 🆗 Response Creators --- Factory functions for responses with pre-filled status and status text
  • 🎏 Stream Response --- Use async generators to build streaming responses for SSE, etc...
  • 🥏 JSON Fetch --- Drop-in replacements for Fetch API classes with first class support for JSON.
  • 🦑 JSON Stream --- Streaming JSON parser/stingifier with first class support for web streams.

Worker Tools also includes a number of polyfills that help bridge the gap between Worker Runtimes:

Fore more visit workers.tools.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].