h3-on-edge
h3-on-edge copied to clipboard
⚡️ Edge workers with straming powered by unjs/h3
⚡️ H3 on the edge
This repo contains examples of unjs/h3 integration with popular runtime platforms.
H3 Web Adapter
With h3 (>= 1.8) you can easily integrate your app with any runtime platform supporting Fetch API (Request
=> Response
).
import { createApp, eventHandler, toWebHandler } from "h3"; // or "https://esm.sh/[email protected]"
const app = createApp();
app.use(
"/",
eventHandler((event) => "H3 works on edge!"),
);
// (Request) => Promise<Response>
const webHandler = toWebHandler(app);
You can virtually return anything from an event handler including web ReadableStream
and Response
!
See ./src/index.ts
for main application and each platform details in next section.
Platforms
Cloudflare Workers
- Deployment
- Entry:
./src/cloudflare.ts
- Config: `./wrangler.toml
- Local dev:
pnpm cloudflare:dev
- Local deploy:
pnpm cloudflare:deploy
Deno
- Deployment
- Entry:
./src/deno.ts
- Local dev:
pnpm deno:dev
- Local deploy:
pnpm deno:deploy --token <deploy_token> --project <project_id>
Bun
- Entry:
./src/bun.ts
- Local dev:
pnpm bun:dev
Lagon
- Deployment
- Entry:
./src/lagon.ts
- Local dev:
pnpm lagon:dev
- Local deploy:
pnpm lagon:deploy
Netlify Edge
- Entry:
./src/netlify
- Config:
./netlify.toml
- Local dev:
pnpm netlify:dev
Setup Local Environment
- Install latest version of Node.js (18 is recommended)
- Enable Node.js corepack using
corepack enable
- Clone repository
- Install dependencies using
pnpm install
- Start Node.js development server using
pnpm dev
License
MIT - Pooya Parsa [email protected]