Dynamic routing and API endpoints in NextJS