telefunc()

Environment: Server.

We add Telefunc to our server by using the Telefunc Server Middleware telefunc():

// server.js

import { telefunc } from 'telefunc'

// Server (Express.js/Fastify/Koa/Hapi/...)
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.