diff --git a/index.js b/index.js index 4fc55f0..64bd950 100644 --- a/index.js +++ b/index.js @@ -253,7 +253,18 @@ prerender.buildApiUrl = function(req) { if (this.protocol) { protocol = this.protocol; } - var fullUrl = protocol + "://" + (this.host || req.headers['x-forwarded-host'] || req.headers['host']) + req.url; + + var host; + if (this.host) { + host = this.host; + } else if (req.headers['x-forwarded-host']) { + // Take the first hostname in case of multiple values + host = req.headers['x-forwarded-host'].replace(/,.*$/, ''); + } else if (req.headers['host']) { + host = req.headers['host']; + } + + var fullUrl = protocol + "://" + host + req.url; return prerenderUrl + forwardSlash + fullUrl; };