aboutsummaryrefslogtreecommitdiff
path: root/routes/index.js
blob: 0fc0d30974276d5730ea6e0898a00a82bb0f9177 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'use strict'

const express = require('express')
const router = express.Router()
const getUserIndex = require('../lib/getUserIndex')

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')
    }

    const flagsStr = `var FLAGS = ${JSON.stringify(flags)};`
    const usersStr = `var USERS = ${JSON.stringify(users)};`

    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