From bfa7fcc582cc0017266f24ee70884cada3d6d01b Mon Sep 17 00:00:00 2001 From: PC Drew Date: Wed, 16 Nov 2016 15:19:17 -0700 Subject: [PATCH] Add additional fields to the client and server request objects to access hostname, protocol, and secure options of the request. On the client side, it looks in the window.location variable for the info. --- packages/react-server/core/ClientRequest.js | 22 +++++++++++++++++++ .../react-server/core/ExpressServerRequest.js | 12 ++++++++++ 2 files changed, 34 insertions(+) diff --git a/packages/react-server/core/ClientRequest.js b/packages/react-server/core/ClientRequest.js index f0929a29c..8d03be5ee 100644 --- a/packages/react-server/core/ClientRequest.js +++ b/packages/react-server/core/ClientRequest.js @@ -63,6 +63,28 @@ class ClientRequest { return decode(this._url.substring(indexOfQuestion + 1)); } + getHostname() { + var hostname = null; + if (typeof window.location.hostname === "string") { + hostname = window.location.hostname; + } + + return hostname; + } + + getProtocol() { + var proto = null; + if (typeof window.location.protocol === "string") { + proto = window.location.protocol.replace(/:/g,''); + } + + return proto; + } + + getSecure() { + return ('https' === this.getProtocol()); + } + getRouteParams() { return this._route.params; } diff --git a/packages/react-server/core/ExpressServerRequest.js b/packages/react-server/core/ExpressServerRequest.js index 1e9a10f89..3fb8640ac 100644 --- a/packages/react-server/core/ExpressServerRequest.js +++ b/packages/react-server/core/ExpressServerRequest.js @@ -20,6 +20,18 @@ class ExpressServerRequest { return this._wrappedRequest.query; } + getHostname() { + return this._wrappedRequest.hostname; + } + + getProtocol() { + return this._wrappedRequest.protocol; + } + + getSecure() { + return this._wrappedRequest.secure; + } + getRouteParams() { return this._route.params; }