From 20530f2cc0fc0187621328e6f6843089bb342ab9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20M=C3=A9tais?= Date: Thu, 4 Sep 2014 18:06:48 +0200 Subject: [PATCH] Fix bug when results folder doesn't exist --- server.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/server.js b/server.js index 9ce354c..876b4e1 100644 --- a/server.js +++ b/server.js @@ -24,12 +24,12 @@ app.use(bodyParser.urlencoded({ extended: false })); // Redirect www.yellowlab.tools to yellowlab.tools (for SEO) app.all('*', function(req, res, next) { - if (req.hostname.match(/^www\.yellowlab\.tools/) !== null ) { + if (req.hostname && req.hostname.match(/^www\.yellowlab\.tools/) !== null) { res.redirect('http://' + req.hostname.replace(/^www\.yellowlab\.tools/, 'yellowlab.tools') + req.url); } else { next(); } -}) +}); // Routes definition app.get('/', indexController); @@ -47,7 +47,11 @@ io.on('connection', function(socket){ waitingQueueSocket(socket, testQueue); }); - +// Create the results folder if it doesn't exist +var resultsPath = 'results'; +if (!fs.existsSync(resultsPath)) { + fs.mkdirSync(resultsPath); +} // Launch the server server.listen(settings.serverPort, function() {