INNER CODE UNIT · TypeScript

handlerToExpress

cisagov/crossfeed · backend/src/api/app.ts:36

const handlerToExpress = (handler) => async (req, res) => {
  const { statusCode, body } = await handler(
    {
      pathParameters: req.params,
      query: req.query,
      requestContext: req.requestContext,
      body: JSON.stringify(req.body || '{}'),
      headers: req.headers,
      path: req.originalUrl
    },
    {}
  );
  try {
    const parsedBody = JSON.parse(body);
    res.status(statusCode).json(parsedBody);
  } catch (e) {
    // Not a JSON body
    res.setHeader('content-type', 'text/plain');

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…