Configure complex routing

I have a Next.js website and a Node.js API. I want to host my site and set up the routing correctly. When someone visits the home page, I want them to see the home page of my Next.js app. If someone goes to a route starting with “/pages/*”, I want them to see the corresponding page on my Next.js app. For all other routes, I want the traffic to go to my API. How can I achieve this setup?