SOFA icon indicating copy to clipboard operation
SOFA copied to clipboard

Not working with Nestjs

Open rafakwolf opened this issue 1 year ago • 2 comments

I'm attempting to use Sofa in a Nestjs app, but the Rest endpoints are not receiving the data from post requests.

Here's an example https://github.com/rafakwolf/nestjs-sofa-poc

rafakwolf avatar May 25 '23 21:05 rafakwolf

Here's how I use it with Nest.

const application = await NestFactory.create(AppModule, {
    bodyParser: true,
    rawBody: true,
  });
import { Request, Response, NextFunction } from 'express';

export function restoreBody(
  req: Request & { rawBody: Uint8Array },
  _res: Response,
  next: NextFunction
) {
  if (req.rawBody) {
    req.body = req.rawBody;
  }
  next();
}

export default restoreBody;
const app = this.httpAdapterHost.httpAdapter.getInstance();

const sofa = useSofa({
  ...
});

app.use('/api', restoreBody, sofa);

2627500295 avatar Jun 30 '23 05:06 2627500295

Is is possible to get a full example of how you use sofa with Nestjs? @2627500295

yuraxdrumz avatar Jul 12 '23 09:07 yuraxdrumz