From 2183d7c4270bc0719ff3adc5c477c1eea4c6f44d Mon Sep 17 00:00:00 2001 From: yoppi Date: Tue, 11 Feb 2014 13:17:43 +0900 Subject: [PATCH] Handle query string --- lib/seoserver.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/seoserver.js b/lib/seoserver.js index 7d4f09b..db73d03 100644 --- a/lib/seoserver.js +++ b/lib/seoserver.js @@ -1,4 +1,5 @@ var express = require('express'), + _url = require('url'), app = express(), args = process.argv.splice(2), port = args[0] !== 'undefined' ? args[0] : 3000, @@ -44,7 +45,14 @@ respond = function(req, res) { url = req.headers.referer; } if (req.headers['x-forwarded-host']) { - url = 'http://' + req.headers['x-forwarded-host'] + req.params[0]; + var path = req.params[0]; + var search = _url.parse(req.url).search; + + if (path.charAt(0) === "/") { + path = path.substring(1, path.length); + } + + url = 'http://' + req.headers['x-forwarded-host'] + '/' + encodeURIComponent(path) + (search ? search : ''); } console.log('url:', url); getContent(url, function(content) {