A very common setup for a side project in 2026: the React or Next.js frontend on Vercel or Netlify, the API on Render or Railway, maybe the docs on GitHub Pages. Each one free, each one with its own address. It works, until the browser gets involved.
What goes wrong with two addresses
Your frontend at myapp.vercel.app calls myapi.onrender.com. To the browser those are different origins, so every request is cross-origin:
- CORS. The API has to send
Access-Control-Allow-Originfor the frontend's exact address, handleOPTIONSpreflight requests for anything that isn't a simple GET and list every header and method you use. Add a preview deployment with its own URL and the list grows. - Cookies. A session cookie set by the API is a cookie for the API's site. Browsers treat it as third-party from the frontend's point of view. More and more of them refuse those. Auth that worked on localhost quietly breaks.
- Two things to share. The URL you put on your CV, your README and your Product Hunt page is the frontend. The API's URL leaks into network tabs and error reports anyway.
Each of these has a workaround. Together they're a weekend.
One domain, two services
The alternative is to stop having two addresses. Put both behind one domain and split by path:
myapp.digitalweb.hostgoes to the frontendmyapp.digitalweb.host/apigoes to the API
The browser now sees one origin. fetch('/api/users') is a same-origin request: no preflight and no CORS headers. Cookies the API sets are first-party. Your frontend code gets simpler too, because the API's base URL is just /api in every environment.
This is a reverse proxy with path routing, the same thing you'd configure in nginx with two location blocks. On DomainDock it's a field on the domain:
The domain's own target serves everything except the paths you add.
Add the domain with the frontend as its target, then under Paths add /api pointing at myapi.onrender.com. It takes effect in a few seconds.
Keep /api, or remove it?
The one decision you have to make is what path the API receives.
By default it gets the full path: a visit to /api/users reaches the API as /api/users. That's right when your backend's routes already start with /api, which is common with Express and FastAPI apps that prefix their routers.
If your API's routes are /users and /orders, turn on Remove /api before forwarding. Then /api/users reaches it as /users. Get this backwards and every API call returns 404, so it's worth a quick test after setting it up.
What matches what
A path matches itself and everything below it. /api catches /api/users and /api/users/42 as well as /api itself. It doesn't catch /apiary, so a page called /apiary stays with the frontend. When paths overlap, the longest wins: with /api and /api/v2, a request to /api/v2/users goes to the /api/v2 service. That makes it easy to move a new version of an API to a different host without touching the old one.
Paths are case-sensitive, like URLs. A domain can have up to 10.
The cleanup in your code
Once both are behind one domain:
- Replace the API base URL with a relative one.
NEXT_PUBLIC_API_URL=https://myapi.onrender.combecomes/api, or disappears. - Remove the CORS configuration from the API, or narrow it to tools that really are on another origin.
- Let session cookies be plain first-party cookies again:
SameSite=Lax, noSameSite=Noneworkarounds.
If the API redirects (after a login, say) to its own address, DomainDock rewrites that redirect to your domain so visitors don't get bounced to onrender.com. Cookies the API scopes to its own address are adjusted the same way.
Things to know
- Each path's target gets the same connection test as the main one when you add it, including whether it speaks HTTPS.
- Health checks and down alerts watch the domain's main target. If only the API is down, visitors hitting
/apiget the status page while the frontend keeps working. - Server-sent events, WebSockets and file uploads go through paths like any other request.
- It's one domain, so it's one password if you turn on password protection. That covers the API too, which matters if a webhook needs to reach it.
The paths guide has the exact matching rules and how to switch an existing path between keeping and removing its prefix.