telefunc()
Environment: server.
The telefunc() function enables you to install a Telefunc middleware into any server.
It's a pure function (no side effects).
You can pass the web standard Request object:
const httpResponse = await telefunc({
// Required
request,
// Optional
context: {
/* Some context */
}
})The
contextparameter is optional and is only needed if you usegetContext(), see API >getContext()> Provide.
Or the Node.js req readable stream:
const httpResponse = await telefunc({
// Required
url: req.originalUrl,
method: req.method,
readable: req,
contentType: req.headers['content-type'] || '',
// Optional
context: {
/* Some context */
}
})The return value httpResponse is a plain JavaScript object with all the information needed to generate the HTTP response, for exampe using the web standard Response object:
const response = new Response(httpResponse.body, {
status: httpResponse.statusCode,
headers: { 'content-type': httpResponse.contentType },
})