question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fastify Swagger + TypeORM break application/x-www-form-urlencoded parsing

See original GitHub issue

I’m submitting a…


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

500 error when a body with application/x-www-form-urlencoded type is sent. Happens when Swagger is used in conjunction with TypeORM.

Expected behavior

application/x-www-form-urlencoded body is parsed.

Minimal reproduction of the problem with instructions

Repo

npm run start:dev, then curl -da=b localhost:3000

Commenting out either the SwaggerModule.setup or TypeOrmModule.forRoot call causes the issue not to occur.

Environment


Nest version: 7.0.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
Summon528commented, Sep 3, 2020

Another temporary workaround (disable built-in bodyParser and enable formbody manually)

  import * as FastifyFormBody from 'fastify-formbody';

  const app = await NestFactory.create<NestFastifyApplication>(
    AppModule,
    new FastifyAdapter(),
    { bodyParser: false },
  );

  app.register(FastifyFormBody as any);
3reactions
kamilmysliwieccommented, Nov 10, 2020
const app = await NestFactory.create<NestFastifyApplication>(
  AppModule,
  new FastifyAdapter(),
);
await app.init(); // <-- this

Adding await app.init() should fix this issue. It seems that the body parser plugin must be registered before fastify-swagger (in fastify v3)

Read more comments on GitHub >

github_iconTop Results From Across the Web

fastify-formbody and fastify-http-proxy are changing ...
I am using fastify to proxy calls to spring boot backend. Using fastify-http-proxy as proxy and application/x-www-form-urlencoded content ...
Read more >
npm - Snyk
@alancnet/fantasy-names · @alexamies/chinesedict-js · @alifd/next · @alpacahq/alpaca-trade-api · @amcharts/amcharts3-angular · @amcharts/amcharts4 ...
Read more >
Search Results - CVE
This vulnerability could allow an attacker to set arbitrary and unexpected keys on the object returned from `JSON5.parse`. The actual impact will depend...
Read more >
Unsupported media type \"application/x-www-form-urlencoded
Fastify, out of the box, parse only application/json payload. To manage forms you need to add these plugins to your project.
Read more >
infinite scroll in react Code Example - Code Grepper
sendFile · jquery delete grand parent of clicked element · react native image fit container · use application/x-www-form-urlencoded in javascript ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found