Server (Hono, Express, ...)
You can integrate Telefunc into any server, most notably servers that use:
Standard Request
You can integrate Telefunc into any server that uses the standard Request object such as Hono, Next.js, Nitro, Nuxt, and SvelteKit.
For example Hono:
// server.js
// Environment: server
import { Hono } from 'hono'
import { telefunc } from 'telefunc'
const app = new Hono()
app.all('/_telefunc', async (c) => {
const httpResponse = await telefunc({ request: c.req.raw })
return new Response(httpResponse.body, {
status: httpResponse.statusCode,
headers: { 'content-type': httpResponse.contentType },
context: {
// You can add any arbitrary contextual information here
}
})
})// server.ts
// Environment: server
import { Hono } from 'hono'
import { telefunc } from 'telefunc'
const app = new Hono()
app.all('/_telefunc', async (c) => {
const httpResponse = await telefunc({ request: c.req.raw })
return new Response(httpResponse.body, {
status: httpResponse.statusCode,
headers: { 'content-type': httpResponse.contentType },
context: {
// You can add any arbitrary contextual information here
},
})
})You can access
contextinside your telefunctions viagetContext().
Node.js req
You can integrate Telefunc into any server that uses the Node.js req readable stream, such as Express and Fastify.
For example Express:
// Environment: server
import express from 'express'
import { telefunc } from 'telefunc'
const app = express()
app.all('/_telefunc', async (req, res) => {
const httpResponse = await telefunc({
url: req.originalUrl,
method: req.method,
readable: req,
contentType: req.headers['content-type'] || '',
context: {
// You can add any arbitrary contextual information here
}
})
res.status(httpResponse.statusCode).type(httpResponse.contentType).send(httpResponse.body)
})// Environment: server
import express from 'express'
import { telefunc } from 'telefunc'
const app = express()
app.all('/_telefunc', async (req, res) => {
const httpResponse = await telefunc({
url: req.originalUrl,
method: req.method,
readable: req,
contentType: req.headers['content-type'] || '',
context: {
// You can add any arbitrary contextual information here
},
})
res.status(httpResponse.statusCode).type(httpResponse.contentType).send(httpResponse.body)
})You can access
contextinside your telefunctions viagetContext().