From a471a984f80a94a57d05120c4a5d5f516b77f7e9 Mon Sep 17 00:00:00 2001 From: Jonathan Cremin Date: Sat, 6 Dec 2014 18:16:31 +0000 Subject: [PATCH] Stop sending headers twice. --- routes/search.js | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/routes/search.js b/routes/search.js index 48d5d50..3994975 100644 --- a/routes/search.js +++ b/routes/search.js @@ -19,31 +19,31 @@ module.exports = function(req, res) { if (!url.host) { req.flash('search-error', 'Paste a music link above to find and share the matches'); res.redirect('/'); - return; - } + } else { + for (var id in services) { + var matched = services[id].match(req.body.url); + if (matched) { + searching = true; + Q.timeout(services[id].parseUrl(req.body.url), 5000).then(function(result) { + if (!result.id) { + req.flash('search-error', 'No match found for this link'); + res.redirect('/'); + } else { + res.redirect("/" + id + "/" + result.type + "/" + result.id); + } + }, function(error) { + if (error.code == "ETIMEDOUT") { + error = new Error("Error talking to music service"); + error.status = "502"; + } else if (!error.status) { + error = new Error("An unexpected error happenend"); + error.status = 500; + } + next(error); + }); - for (var id in services) { - var matched = services[id].match(req.body.url); - if (matched) { - searching = true; - Q.timeout(services[id].parseUrl(req.body.url), 5000).then(function(result) { - if (!result.id) { - req.flash('search-error', 'No match found for this link'); - res.redirect('/'); - } - res.redirect("/" + id + "/" + result.type + "/" + result.id); - }, function(error) { - if (error.code == "ETIMEDOUT") { - error = new Error("Error talking to music service"); - error.status = "502"; - } else if (!error.status) { - error = new Error("An unexpected error happenend"); - error.status = 500; - } - next(error); - }); - - break; + break; + } } } if (!searching) {