Reverse Proxy and WebServer Layer
Nginx allows for wildcards for naming server blocks
This allows all that traffic to hit a specific port regardless of subdomain.
Application Layer
Plain express.js - http://expressjs.com/en/5x/api.html#req.subdomains
// Host: "tobi.ferrets.example.com"
console.dir(req.subdomains) // <--- we can extract the subdomain from url
// => ["ferrets", "tobi"]
With other dependencies, this could simplify the code:
https://www.npmjs.com/package/express-subdomain
//the api middleware flow
router.use(checkUser);
router.use(subdomain('*.v1', v1Routes)); // routing based on subdomain wildcard!
router.use(subdomain('*.v2', v2Routes));
Reverse Proxy and WebServer Layer
Nginx allows for wildcards for naming server blocks
This allows all that traffic to hit a specific port regardless of subdomain.
Application Layer
Plain express.js - http://expressjs.com/en/5x/api.html#req.subdomains
With other dependencies, this could simplify the code:
https://www.npmjs.com/package/express-subdomain