Skip to content

Runtime Adapters

Deploy the same application code to any runtime.

Node.js

import { createServer } from "node:http";
import { createApp } from "@rune/core";
const app = createApp();
app.registerModule(AppModule);
const server = createServer(async (req, res) => {
const url = `http://${req.headers.host}${req.url}`;
const request = new Request(url, {
method: req.method,
headers: req.headers as Record<string, string>,
});
const response = await app.fetch(request);
res.statusCode = response.status;
response.headers.forEach((v, k) => res.setHeader(k, v));
res.end(await response.text());
});
server.listen(3000);

Bun

import { createApp } from "@rune/core";
const app = createApp();
app.registerModule(AppModule);
Bun.serve({
port: 3000,
fetch: (req) => app.fetch(req),
});

Hono

import { Hono } from "hono";
import { toHono } from "@rune/adapter-hono";
import { createApp } from "@rune/core";
const app = createApp();
app.registerModule(AppModule);
const hono = toHono(app);
export default hono;

Fastify

import Fastify from "fastify";
import { toFastify } from "@rune/adapter-fastify";
import { createApp } from "@rune/core";
const app = createApp();
app.registerModule(AppModule);
const fastify = toFastify(app, Fastify());
fastify.listen({ port: 3000 });

Express

import express from "express";
import { toExpress } from "@rune/adapter-express";
import { createApp } from "@rune/core";
const app = createApp();
app.registerModule(AppModule);
const expressApp = toExpress(app, express());
expressApp.listen(3000);

Koa

import Koa from "koa";
import { toKoaMiddleware } from "@rune/adapter-koa";
import { createApp } from "@rune/core";
const app = createApp();
app.registerModule(AppModule);
const koa = new Koa();
koa.use(toKoaMiddleware(app));
koa.listen(3000);

h3

import { createServer } from "node:http";
import { toNodeHandler } from "h3/node";
import { toH3 } from "@rune/adapter-h3";
import { createApp } from "@rune/core";
const app = createApp();
app.registerModule(AppModule);
const h3App = toH3(app);
createServer(toNodeHandler(h3App)).listen(3000);

Cloudflare Workers

import { toCloudflareWorker } from "@rune/adapter-cloudflare-workers";
import { createApp } from "@rune/core";
const app = createApp();
app.registerModule(AppModule);
export default { fetch: toCloudflareWorker(app) };

Cloudflare Pages

import { toCloudflarePagesFunction } from "@rune/adapter-cloudflare-pages";
import { createApp } from "@rune/core";
const app = createApp();
app.registerModule(AppModule);
export const onRequest = toCloudflarePagesFunction(app);

AWS Lambda (API Gateway / Function URL)

import { toAwsLambda } from "@rune/adapter-aws-lambda";
import { createApp } from "@rune/core";
const app = createApp();
app.registerModule(AppModule);
export const handler = toAwsLambda(app);

Lambda@Edge (CloudFront)

import { toLambdaEdgeHandler, toAPIGatewayHandler } from "@rune/adapter-lambda-edge";
import { createApp } from "@rune/core";
const app = createApp();
app.registerModule(AppModule);
// For CloudFront events
export const edgeHandler = toLambdaEdgeHandler(app);
// For API Gateway events
export const apiHandler = toAPIGatewayHandler(app);

Service Worker

import { toServiceWorker } from "@rune/adapter-service-worker";
import { createApp } from "@rune/core";
const app = createApp();
app.registerModule(AppModule);
self.addEventListener("fetch", toServiceWorker(app));

Netlify Edge / Functions

import { toNetlifyEdge, toNetlifyFunction } from "@rune/adapter-netlify";
import { createApp } from "@rune/core";
const app = createApp();
app.registerModule(AppModule);
// Edge Functions
export default toNetlifyEdge(app);
// Serverless Functions
export const handler = toNetlifyFunction(app);

Vercel Edge

import { toVercelEdge } from "@rune/adapter-vercel";
import { createApp } from "@rune/core";
const app = createApp();
app.registerModule(AppModule);
export const config = { runtime: "edge" };
export default toVercelEdge(app);

Runtime Test Coverage

Each runtime adapter has integration tests under runtime-tests/<runtime>/ that validate the adapter in its target runtime:

RuntimeTest directoryAdapter testedExecution
Vercelruntime-tests/vercel/toVercelEdgeCompiled → direct fn import
Cloudflareruntime-tests/cloudflare/toCloudflareWorkerCompiled → direct fn import
Denoruntime-tests/deno/Deno.serve + app.fetchBun bundle → deno run process
Netlifyruntime-tests/netlify/toNetlifyFunctionCompiled → direct fn import
Node.jsruntime-tests/node/createNodeServerbun run child process + HTTP
Node.js + TSruntime-tests/node-ts/Raw app.fetch()Direct TypeScript import (Bun)
h3runtime-tests/h3/toH3 + toNodeHandlerbun run child process + HTTP

Run individual test suites:

Terminal window
bun run test:runtime:vercel
bun run test:runtime:cloudflare
bun run test:runtime:deno
bun run test:runtime:netlify
bun run test:runtime:node
bun run test:runtime:node-ts
bun run test:runtime:h3