Adapters

Deno

Run your h3 apps in Deno Deploy

You can directly host your h3 applications to Deno Deploy using Web Adapter.

Usage

Create app entry:

app.mjs
import { createApp, defineEventHandler } from "h3";

export const app = createApp();

app.use(defineEventHandler(() => "Hello world!"));

Create entry for Deno Deploy:

deno.mjs
import { toWebHandler } from "h3";
import { app } from "./app.mjs";

Deno.serve(toWebHandler(app));

Create an import_map.json:

import_map.json
{
  "imports": {
    "h3": "https://esm.sh/h3@latest"
  }
}

Finally, use deno run to locally preview:

terminal
deno run --allow-net ./deno.mjs

To deploy, use deployctl deploy:

terminal
deployctl deploy --prod --exclude=node_modules --import-map=./import_map.json ./deno.mjs

WebSocket support

Read more in crossws.unjs.io/adapters/deno.
import wsAdapter from "crossws/adapters/deno";

const handler = toWebHandler(app);

const { handleUpgrade } = wsAdapter(app.websocket);

Deno.serve((request) => {
  if (request.headers.get("upgrade") === "websocket") {
    return handleUpgrade(request);
  }
  return handler(request);
});

See pi0/h3-on-edge demo for a fully working example (deployment).