Reputation: 291
I have a simple pages/api/thumbnail.js
file with a handler:
export default async function handler(req, res) {
console.dir(req.params)
// ...
}
On a pure express server, it is possible to have a "path parameter", but on NextJS I got a error 404 if a try to pass some path on my API.
Example:
http://localhost:3000/api/thumbnail >> OK, it works
Now with a path:
http://localhost:3000/api/thumbnail/something >> ERROR, 404 not found!
Using NextJS API is it possible to use path parameters or only query string?
PS. I am using Vercel, if using a rewrite is the only solution, its acceptable to me.
Upvotes: 2
Views: 9692
Reputation: 2468
You can try adding three dots on the file name like this: pages/api/thumbnail/[[...params]].js
Then you can load the params in your handler from req.query
Source: optional-catch-all-api-routes in next.js docs
Upvotes: 5