Starter template for uttp.
- Clone the template:
npx degit sachinraja/uttp/examples/starter
-
Replace all instances of
uttp-starter
with your package name. -
Start developing! Most of the work should be done in
src/handler.ts
.
npm install uttp-starter
Node
import { createServer } from 'http'
import { nodeHandler } from 'uttp-starter/adapters/node'
const server = createServer(await nodeHandler(/* options */))
Example: scripts/node-server.ts
Express
import { expressHandler } from 'uttp-starter/adapters/express'
app.use(await expressHandler(/* options */))
Fastify
import { getFastifyPlugin } from 'uttp-starter/adapters/fastify'
server.register(await getFastifyPlugin(/* options */))
Fetch
// Cloudflare Workers example
import { fetchHandler } from 'uttp-starter/adapters/fetch'
export default {
fetch: await fetchHandler(/* options */),
}
h3
import { h3Handler } from 'uttp-starter/adapters/h3'
app.use(await h3Handler(/* options */))
Nuxt
import { h3Handler } from 'uttp-starter/adapters/h3'
const eventHandler = await h3Handler(/* options */)
export default eventHandler
Koa
import { koaHandler } from 'uttp-starter/adapters/koa'
app.use(await koaHandler(/* options */))
AWS Lambda
import { awsLambdaHandler } from 'uttp-starter/adapters/aws-lambda'
// requires es modules/top-level await/Node.js 14 runtime
export const handler = await awsLambdaHandler(/* options */)