在我的应用程序中,我正在创建多个用户,user1,user2...
并希望为每个用户分配子域,例如,user1.xyz.com,user2.xyz.com ...
以下是该应用程序的要求:
1)在用户向应用程序注册后动态创建这些子域
2)GET user1.xyz.com
应该拨打一条类似的路线/user1/home
我已经看到了npm模块https://www.npmjs.com/package/express-subdomain,但看起来它仅适用于静态子域。
找到了满足要求的包装:
https://github.com/edwardhotchkiss/subdomain。
app.use(subdomain({ base : 'localhost', removeWWW : true }));
app.get('/subdomain/:name', Controller}); //GETs user1.localhost and user1 can be used as parameter using req.params.name
例如。
app.get('/subdomain/:name',function(req,res){
var name = req.params.name;
res.send(name);
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句