Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kuttu's avatar
Level 1

Best way to host API routes and client app on same domain

I'm developing a web app, using Laravel to develop the API and admin panel, and another framework for the web client app (next.js/now). I'd optimally like to host them all on the same url: myawesomeapp.com.

Api requests would optimally go to myawesomeapp.com/api/user/ (for example), and the actual web app would route to my next.js, hosted elsewhere, (routes like myawesomeapp.com/profile for example). I assume since much of the server layer is abstracted away if I deploy with Forge, so this wouldn't be possible. However the next best option would be putting my API and admin routes behind subdomains - api.myawesomeapp.com and admin.myawesomeapp.com respectively.

However I'm curious how I could ensure that routes to the root url, simply https://shareit.onl/ https://appvn.onl/ are passed through to my client app (next.js hosted with now)

0 likes
2 replies
frankincredible's avatar

You're almost certainly going to have to use a subdomain.

For example, api.myawesomeapp.com/v1/user

That way you could set your DNS settings to point api.myawesomeapp.com to your API's IP, and myawesomeapp.com (or www.myawesomeapp.com) to your frontend's IP.

Please or to participate in this conversation.