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ā€¢7mo ago
Project ID: N/A
Solution
Fragly
Fraglyā€¢7mo ago
you mean wildcard subdomains?
Fragly
Fraglyā€¢7mo ago
if so then yea you just pop in *.coolstore.com as a custom domain
š–­š—‚š—€š—š—š–Ŗš—Žš—‡š–¦š—“
and make backend handle that request that from which sub domain name right?
Fragly
Fraglyā€¢7mo ago
yes!
Fragly
Fraglyā€¢7mo ago
no problem :)
Brody
Brodyā€¢7mo ago
your backend framework would need to be able to do hostname routing, most frameworks support this
š–­š—‚š—€š—š—š–Ŗš—Žš—‡š–¦š—“
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ā€¢7mo 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
š–­š—‚š—€š—š—š–Ŗš—Žš—‡š–¦š—“
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ā€¢7mo ago
<:mommy_confused:1023749002069540935> you're using two different frameworks for building your apps?
š–­š—‚š—€š—š—š–Ŗš—Žš—‡š–¦š—“
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ā€¢7mo 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ā€¢7mo ago
I've tried using caddy before, didn't like it, made my own reverse proxy instead
š–­š—‚š—€š—š—š–Ŗš—Žš—‡š–¦š—“
i never heard it before but ill try to research it! tysm šŸ™‡ā€ā™‚ļø
Brody
Brodyā€¢7mo ago
well thats not something i can recommend lol (replying to fragly)
Fragly
Fraglyā€¢7mo ago
I live on the edge
š–­š—‚š—€š—š—š–Ŗš—Žš—‡š–¦š—“
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ā€¢7mo ago
happy to help, and good luck! :)
Brody
Brodyā€¢7mo ago
sounds good, i wrote that caddyfile so if you have questions feel free to ask
š–­š—‚š—€š—š—š–Ŗš—Žš—‡š–¦š—“
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ā€¢7mo ago
I gave you a ready made example that uses caddy, you aren't going to go that route?
š–­š—‚š—€š—š—š–Ŗš—Žš—‡š–¦š—“
yeah i already seen that but i still confuse about reverse proxy a bit maybe not a bit
Brody
Brodyā€¢7mo ago
well either way, you would absolutely want to use the private domain within the reverse proxy
š–­š—‚š—€š—š—š–Ŗš—Žš—‡š–¦š—“
so i need to add WEB_HOST_INTERNAL in private networking?
Brody
Brodyā€¢7mo ago
you'd need to set that to one of the internal domains
š–­š—‚š—€š—š—š–Ŗš—Žš—‡š–¦š—“
like create subdomain named internal-admin.up.railway.app in admin service and make caddy redirect to that web host right?
Brody
Brodyā€¢7mo 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
Brody
Brodyā€¢7mo ago
I'm using example names and domains, substitute for your domain names where applicable
Brody
Brodyā€¢7mo 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
š–­š—‚š—€š—š—š–Ŗš—Žš—‡š–¦š—“
so .internal can be used for this situation right?
Brody
Brodyā€¢7mo 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
Brody
Brodyā€¢7mo 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