R
Railwayā€¢13mo ago
Yomyam

Handle Dynamic Subdomain

is it possible to make railway handle dynamic sub domains like [shop_name].coolstore.com
Solution:
you mean wildcard subdomains?
Jump to solution
37 Replies
Percy
Percyā€¢13mo ago
Project ID: N/A
Solution
Fragly
Fraglyā€¢13mo ago
you mean wildcard subdomains?
Fragly
Fraglyā€¢13mo ago
if so then yea you just pop in *.coolstore.com as a custom domain
Yomyam
YomyamOPā€¢13mo ago
and make backend handle that request that from which sub domain name right?
Fragly
Fraglyā€¢13mo ago
yes!
Yomyam
YomyamOPā€¢13mo ago
lovelyamazed ok! i'll try that tysm
Fragly
Fraglyā€¢13mo ago
no problem :)
Brody
Brodyā€¢13mo ago
your backend framework would need to be able to do hostname routing, most frameworks support this
Yomyam
YomyamOPā€¢13mo ago
have more question i have 2 web app (admin, store) so if i want to make whoever access website with sub domain, i want to make it render store but if user access coolstore.com or dashboard.coolstore.com i want to make it render admin web instead how to do that?
Fragly
Fraglyā€¢13mo ago
I've done this before You just check whether the subdomain you received is dashboard ( and it's on the host coolstore.com in case you add a way to configure custom domains in the future ) and then if it is simply render the dashboard page if the subdomain isn't coolstore.com ( or on your host ) then route it where it needs to go
Yomyam
YomyamOPā€¢13mo ago
hm any example? i still don't get where should i route them with something like if user redirect 'foo.coolstore.com' its will render store page using Nuxt 3 but if user redirect to 'dashboard.coolstore.com' its will render admin management that using Next.js instead
Fragly
Fraglyā€¢13mo ago
<:mommy_confused:1023749002069540935> you're using two different frameworks for building your apps?
Yomyam
YomyamOPā€¢13mo ago
different team sir like team 1 making store site and team 2 making admin site but its just theory actually i don't know, just give example šŸ¤£ maybe 2 nextjs projects will nginx solve this problem?
Brody
Brodyā€¢13mo ago
use caddy, heres an example that will get you 80% of the way there https://github.com/brody192/reverse-proxy/blob/host-matching/Caddyfile fragly time to learn caddy
Fragly
Fraglyā€¢13mo ago
I've tried using caddy before, didn't like it, made my own reverse proxy instead
Yomyam
YomyamOPā€¢13mo ago
i never heard it before but ill try to research it! tysm šŸ™‡ā€ā™‚ļø
Brody
Brodyā€¢13mo ago
well thats not something i can recommend lol (replying to fragly)
Fragly
Fraglyā€¢13mo ago
I live on the edge
Yomyam
YomyamOPā€¢13mo ago
don't mind me i'm just 1 year experience with web dev that try to make some lil big project xd ill update this forum later if its work perfectly or have more question that related this topic tysm you both again salute
Fragly
Fraglyā€¢13mo ago
happy to help, and good luck! :)
Brody
Brodyā€¢13mo ago
sounds good, i wrote that caddyfile so if you have questions feel free to ask
Yomyam
YomyamOPā€¢13mo ago
about redirect when user access [shop].coolshop.com i need to make nginx handling it and redirect user to store service by using private ip right? or use public ip
No description
Brody
Brodyā€¢13mo ago
I gave you a ready made example that uses caddy, you aren't going to go that route?
Yomyam
YomyamOPā€¢13mo ago
yeah i already seen that but i still confuse about reverse proxy a bit maybe not a bit
Brody
Brodyā€¢13mo ago
well either way, you would absolutely want to use the private domain within the reverse proxy
Yomyam
YomyamOPā€¢13mo ago
so i need to add WEB_HOST_INTERNAL in private networking?
Brody
Brodyā€¢13mo ago
you'd need to set that to one of the internal domains
Yomyam
YomyamOPā€¢13mo ago
like create subdomain named internal-admin.up.railway.app in admin service and make caddy redirect to that web host right?
Brody
Brodyā€¢13mo ago
for a simplistic overview, try to get just this sort of thing working shop.domain.com would proxy to shop.railway.internal domain.com would proxy to dashboard.railway.internal
Yomyam
YomyamOPā€¢13mo ago
oh alright
Brody
Brodyā€¢13mo ago
I'm using example names and domains, substitute for your domain names where applicable
Yomyam
YomyamOPā€¢13mo ago
alright i get it now šŸ˜­ šŸ™‡
Brody
Brodyā€¢13mo ago
that's a public url, use the private domains or else you will be subject to network fees on the two services that you are trying to proxy to
Yomyam
YomyamOPā€¢13mo ago
so .internal can be used for this situation right?
Brody
Brodyā€¢13mo ago
yes, there are no network fees for a service that is only communicated to via the private network your proxy service is exposed publicly and that is the only service between the 3 that should have network fees
Yomyam
YomyamOPā€¢13mo ago
Brody
Brodyā€¢13mo ago
wish I still had the railway project as a demo that went along with the caddyfile that I sent above, but unfortunately I don't, and I don't have the time right now to set that back up
Want results from more Discord servers?
Add your server