Skip to content
← Back to Community
Is there a way to add a dynamic subdomain?
Profile icon
programmeruser

Is there a way to add a dynamic subdomain?

Voters
Profile icon
programmeruser
Comments
hotnewtop
Profile icon
ch1ck3n

not in replit

but if youre hosting on your own machine

app.get('/', function (req, res) { var domain = req.get('host').match(/\w+/); // e.g., host: "subdomain.website.com" // the regex /\w+/ gets the subdomain eg. "fat.cow.com" "fat" if (domain) var subdomain = domain[0]; // Use "subdomain" | [0] because the expression returns an array and we want to get the first subdomain // now your code, where the dynamic subdomain is stored in the variable "subdomain" });
Profile icon
programmeruser

@ch1ck3n thanks for the tip, but I don't feel like hosting on my own pc. I'll try glitch

Profile icon
ch1ck3n

@programmeruser well then you cant

unless you can ask in feedback to add support for subdomains

https://replit.canny.io/hacker-board