1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

NestJSで413エラー(Request Entity Too Large)が発生した際の解決方法

Posted at

はじめに

先日、運用中のNestJSのアプリケーションで413エラー(Request Entity Too Large)が発生しました。
初めて遭遇したエラーでしたので、原因と解決方法について残しておきます。

環境

NestJS 8.0.0
Express.js
TypeScript

問題の原因

413エラー(Request Entity Too Large)は、クライアントから送信されたリクエストのボディサイズが、サーバー側で設定されている最大サイズを超えた場合に起こります。

Express.jsのbody-parserミドルウェアは、デフォルトで100KBの制限を設けており、今回はこれを超えるリクエストであったため発生していました。

解決方法

リクエストボディのサイズ制限を200KBに上げて解消

const app = await NestFactory.create<NestExpressApplication>(AppModule)

app.use(express.json({ limit: '200kb' }))
app.use(express.urlencoded({ limit: '200kb', extended: true }))
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?