首页 > 解决方案 > vhost 正在继承其他路由

问题描述

我正在尝试为每个虚拟主机使用一组不同的路由

module.exports = function(app) {

    app.use(vhost('www.example.com', exampleRoutes))
    app.use(vhost('*.example.com', subdomainRoutes))

}

我的问题是 www.example 也在使用来自subdomainRoutes的路由 我需要以某种方式指定如果我在 www 那么只有exampleRoutes应该工作

更新。看起来我可以使用正则表达式。我需要类似的东西

不是(www.example.com),但我对正则表达式很糟糕:(

标签: expressvhosts

解决方案


把这个放在这里以防有人需要。

const regex = new RegExp('^(?!.*www.example.*).*$');
app.use(vhost(regex, subdomainRoutes))

推荐阅读