Custom domains through NGINX reverse proxy and Next.js app

We’re running a Next.js app on Vercel where users get access to a custom subdomain with their profile — ie jason.mysite.com.

We’re trying to build the use case here (SSL for Custom Domains · Fly) where paid users get to link their custom domain to the existing subdomain.

Deployed the basic NGINX reverse proxy outlined here (GitHub - fly-apps/nginx: A fly app nginx config) to Fly and now trying to pass the original host header through to map that in our db to the custom domain configed by the user.

How do we properly parse out the X-Forwarded-Host header in our app?

I don’t have much experience with next.js, but I think getServerSideProps does what you want. It receives a context argument with a req property containing the incoming request. You can get the header from that, like req.header('X-Forwarded-Host'), then use that to fetch the custom domain in your db.

Do you have a separate api or is it all inside next.js?