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

Lef*_*ver 8 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
Run Code Online (Sandbox Code Playgroud)

但是我如何获取用户向服务器发出的请求 url ???

小智 8

request.protocol只需这样做

    exports.nameOfFunction = function(request, response){
    var proto = request.protocol;
    console.log(proto);
}
Run Code Online (Sandbox Code Playgroud)