Adapters

Plain

Run h3 servers into any unknown runtime!

There might be cases where your runtime is neither Node.js or Web compatible. Using plain adapter you can have an object input/output interface.

This can be also be particularly useful for testing your server or running inside lambda-like environments.

Usage

First, create app entry:

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

export const app = createApp();

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

Create plain entry:

plain.mjs
import { toPlainHandler } from "h3";
import { app } from "./app.mjs";

export const handler = toPlainHandler(app);

Local testing

You can test adapter using any JavaScript runtime.

plain.test.mjs
import { handler } from "./plain.mjs";

const response = await handler({
  method: "GET",
  path: "/",
  headers: {
    "x-test": "test",
  },
  body: undefined,
  context: {},
});

Example response:

{
  status: 200,
  statusText: '',
  headers: [ [ 'content-type', 'text/html' ] ],
  body: 'Hello world!'
}