【问题标题】:what is the request object in browsersync middleware: function(req, res, next())browsersync 中间件中的请求对象是什么:function(req, res, next())
【发布时间】:2016-01-20 15:12:46
【问题描述】:

Browsersync 提到以下内容。

有谁知道请求对象的属性是什么?例如如何获取请求的 Host 属性?

 middleware: function (req, res, next) {
     //the following prints undefined - where can we learn about res, req and next()
     console.log(res.getHeader('Host'));
 }

【问题讨论】:

    标签: gulp connect browser-sync


    【解决方案1】:

    它似乎是一个常规的 Node Http.ClientRequest 对象:

    https://nodejs.org/dist/latest-v6.x/docs/api/http.html#http_class_http_clientrequest

    例如,'headers' 属性只是一个普通的 JS 对象:

    req.headers['host']
    

    应该给你主机。

    您上面的代码示例正在尝试获取响应标头,而不是请求标头。

    【讨论】:

    • 不同的问题。你知道如何获取协议来区分http和https吗?
    猜你喜欢
    • 1970-01-01
    • 2015-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-09
    • 2022-12-11
    • 1970-01-01
    相关资源
    最近更新 更多