【问题标题】:vhost is inheriting other routesvhost 正在继承其他路由
【发布时间】:2020-01-09 18:59:17
【问题描述】:

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

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)但我对正则表达式很糟糕:(

【问题讨论】:

    标签: express vhosts


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2019-02-19
      • 1970-01-01
      • 1970-01-01
      • 2013-11-28
      • 2022-06-21
      • 2016-11-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多