API Routes Response Size Limited to 4MB
API Route
is limited to send a response
that is less than 4MB
.
API Routes
in NextJS are designed to deliver quick responses and are not built to support the transmission of large amounts of data.
If you must send API response greater than the limit, you have to increase the limit via the responseLimit
config.
405
Method Not AllowedThis is caused by export function in /api
route being either one of two things:
default export
instead of individual export for HTTP methods like export async function POST()
GET
, POST
, PUT
, DELETE
, and Option
CORS
Error to /api
endpointThis is caused by missing CORS config on /api/route.ts
import { NextResponse } from "next/server"; export async function OPTIONS(request: Request) { const allowedOrigin = request.headers.get("origin"); const response = new NextResponse(null, { status: 200, headers: { "Access-Control-Allow-Origin": allowedOrigin || "*", "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS", "Access-Control-Allow-Headers": "Content-Type, Authorization, X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Date, X-Api-Version", "Access-Control-Max-Age": "86400", }, }); return response; }
404
Page Not FoundWhen you get a 404
response on an api route call when multiple HTTP methods coexist on a route
file
route
file, other methods that were previously working will also break