在node.js中如何获取请求对象的协议?

时间:2017-02-16 04:31:24

标签: node.js

const URL = require('url').URL;
const myURL = new URL('https://example.org/foo');

console.log(myURL.href);     // https://example.org/foo
console.log(myURL.protocol); // https:
console.log(myURL.hostname); // example.org
console.log(myURL.pathname); // /foo

但是如何获取用户对服务器的请求URL ???

1 个答案:

答案 0 :(得分:1)

只需像request.protocol那样

    exports.nameOfFunction = function(request, response){
    var proto = request.protocol;
    console.log(proto);
}