From a6a4ddc10ba1a458b94b13c59a4081e9ce1e5b33 Mon Sep 17 00:00:00 2001 From: Noah Loomans Date: Fri, 26 May 2017 18:35:51 +0200 Subject: Add emergency redirect --- routes/index.js | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) (limited to 'routes') diff --git a/routes/index.js b/routes/index.js index a65ac69..0fc0d30 100644 --- a/routes/index.js +++ b/routes/index.js @@ -2,24 +2,33 @@ const express = require('express') const router = express.Router() -const users = require('../lib/getUserIndex') +const getUserIndex = require('../lib/getUserIndex') -/* GET home page. */ -router.get(['/', '/s/*', '/t/*', '/r/*', '/c/*'], function (req, res, next) { - const isBeta = process.env.BETA === '1' +getUserIndex().then(users => { + /* GET home page. */ + router.get(['/', '/s/*', '/t/*', '/r/*', '/c/*'], function (req, res, next) { + const isBeta = process.env.BETA === '1' - let flags = [] - if (isBeta) { - flags.push('BETA') - flags.push('NO_FEATURE_DETECT') - } else if (req.query.nfd != null) { - flags.push('NO_FEATURE_DETECT') - } + let flags = [] + if (isBeta) { + flags.push('BETA') + flags.push('NO_FEATURE_DETECT') + } else if (req.query.nfd != null) { + flags.push('NO_FEATURE_DETECT') + } - const flagsStr = `var FLAGS = ${JSON.stringify(flags)};` - const usersStr = `var USERS = ${JSON.stringify(users.users)};` + const flagsStr = `var FLAGS = ${JSON.stringify(flags)};` + const usersStr = `var USERS = ${JSON.stringify(users)};` - res.render('index', { flagsStr, usersStr, isBeta }) + res.render('index', { flagsStr, usersStr, isBeta }) + }) +}, error => { + console.error('Unable to get user info, emergency redirect!') + console.error('Error:', error) + + router.get(['/', '/s/*', '/t/*', '/r/*', '/c/*'], function (req, res, next) { + res.redirect('http://www.meetingpointmco.nl/Roosters-AL/doc/') + }) }) module.exports = router -- cgit v1.1