README
Overview
This is a reproduce-repo for a bug within NextJS API routes.
The bug is essentially a big difference between the DEV environment and the PROD environment in NextJS.
When only a GET and PUT handlers are defined for a given API route, only the GET handler will work in a PROD environment.
Steps to reproduce
- Clone this repo (or create an app using
create-next-appwith all default options) - Create a
route.tsfile insrc/app/api/anything - Make 2 functions for handling the
PUTandGETmethods - Run
npm run devandcurl -X PUT http://localhost:3000/api/testto make sure it doesn't produce an error - Close the dev server
- Run
npm run build && npm run startto start the optimized server. - Perform the same curl request using
curl -X PUT http://localhost:3000/api/test - The server returns an HTML page about a 405 error.
Expected behavior
The change in environment shouldn't affect the behavior of API routes.
Credits
Credits to Gede Dewo Wahyu M.W for discovering this here