JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q40480F
  • License MIT

Use h3 in a (Cloudflare) worker

Package Exports

  • h3-worker

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (h3-worker) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

h3-worker (WIP - not fit for production)

Use h3 in a (Cloudflare) worker!

This little package uses some helpers from h3 and unenv to make h3 apps work in a Cloudflare worker environment.

Install

# Using npm
npm install h3-worker

# Using yarn
yarn add h3-worker

Usage

  • Set up your Cloudflare worker project - I recommend worker-typescript-template
  • Check out the h3 docs
  • Write some routes and use the handleEvent method from h3-worker to respondWith

** Note that you need to put the most specific routes first

import { createApp, handleEvent } from 'h3-worker'

const app = createApp()

app.use('/', () => 'Hello world')
app.use('/json', () => ({ hello: 'JSON' }))

addEventListener('fetch', (event) => {
  event.respondWith(handleEvent(event, app, { basePath: '', sortStack: true }))
})

TaDa!