@aiendpoint/serve
v0.1.0
Published
Serve your /ai endpoint from any JS/TS framework - Express, Fastify, Next.js, Hono, NestJS
Maintainers
Readme
@aiendpoint/serve
Serve your /ai endpoint from any JS/TS framework. One package, one install.
Install
npm install @aiendpoint/serveUsage
Express
import express from 'express'
import { aiendpoint } from '@aiendpoint/serve/express'
const app = express()
app.use(aiendpoint({ spec: './ai.json' }))
app.listen(3000)Fastify
import Fastify from 'fastify'
import { aiendpoint } from '@aiendpoint/serve/fastify'
const app = Fastify()
app.register(aiendpoint, { spec: './ai.json' })
app.listen({ port: 3000 })Next.js (App Router)
// app/ai/route.ts
import { aiendpoint } from '@aiendpoint/serve/next'
export const GET = aiendpoint({ spec: './ai.json' })Hono
import { Hono } from 'hono'
import { aiendpoint } from '@aiendpoint/serve/hono'
const app = new Hono()
app.use(aiendpoint({ spec: './ai.json' }))
export default appNestJS
NestJS uses Express under the hood. Use the Express adapter:
// main.ts
import { aiendpoint } from '@aiendpoint/serve/express'
app.use(aiendpoint({ spec: './ai.json' }))Options
All adapters accept the same options:
aiendpoint({
spec: './ai.json', // path to spec file, or inline object
path: '/ai', // route path (default: '/ai')
maxAge: 3600, // Cache-Control max-age in seconds (default: 3600)
})Generate ai.json
npx @aiendpoint/cli init --openapi https://your-api.com/openapi.json
npx @aiendpoint/cli init # interactive wizardCustom adapter
For frameworks not listed above, use the shared utilities:
import { loadSpec, cacheHeader } from '@aiendpoint/serve/handler'
const spec = loadSpec('./ai.json')
// serve `spec` as JSON with header `Cache-Control: ${cacheHeader(3600)}`