如何使用node express为每个用户创建动态子域?

问题描述:

在注册时,我想在username.example.com上向用户提供其个人资料和应用程序我已经在我的域名提供商的网站上创建了通配符dns.

On signup, I want to give user his profile and application at username.example.com I have already created wild-card dns at my domain provider website.

我该怎么做?

如果将Node.js与Express.js结合使用,则:

If using Node.js with Express.js, then:

router.get('/', function (req, res) { 
    var domain = req.get('host').match(/\w+/); // e.g., host: "subdomain.website.com"
    if (domain)
       var subdomain = domain[0]; // Use "subdomain"
    ...
});