telefunc()

Environment: server.

We install Telefunc by using Telefunc's server middleware telefunc():

// server.js
 
// Server (Express.js/Fastify/...)
 
import { telefunc } from 'telefunc'
 
// Telefunc middleware
app.all('/_telefunc', async (req, res) => {
  const httpResponse = await telefunc({
    // HTTP Request URL, which is '/_telefunc' if we didn't modify config.telefuncUrl
    url: req.url,
    // HTTP Request Method (GET, POST, ...)
    method: req.method,
    // HTTP Request Body, which can be a string, buffer, or stream
    body: req.body,
    // Optional
    context: {
      /* Some context */
    }
  })
  const { body, statusCode, contentType } = httpResponse
  res.status(statusCode).type(contentType).send(body)
})

The context parameter is optional and is only needed if we use getContext(), see API > getContext() > Provide.