Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working with Nestjs #1346

Open
rafakwolf opened this issue May 25, 2023 · 2 comments
Open

Not working with Nestjs #1346

rafakwolf opened this issue May 25, 2023 · 2 comments

Comments

@rafakwolf
Copy link

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

@2627500295
Copy link

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);

@yuraxdrumz
Copy link

yuraxdrumz commented Jul 12, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants