Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

h3-worker

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

h3-worker

Use h3 in a (Cloudflare) worker

  • 0.0.18
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

h3-worker

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
import { createApp, handleEvent } from 'h3-worker'

// Create the app
const app = createApp()

// Add some routes (no need to worry about order)
app.use('/', () => 'Hello world')
app.use('/json', () => ({ hello: 'JSON' }))

// Type the body if you like
app.use<{ firstName: string }>('/first-name', (req) => {
  const { body } = req
  return `Hi ${body.firstName}`
})

// Add the event listener
addEventListener('fetch', (event) => {
  // Respond with a handleEvent() call, passing in the event and your app. Options are optional
  event.respondWith(handleEvent(event, app, { basePath: '', sortStack: true }))
})

TaDa!

Keywords

FAQs

Package last updated on 30 Oct 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc