aboutsummaryrefslogtreecommitdiff
path: root/src/server/routes/index.js
blob: d2267ba9168dfea5fdc5a956e623aa3ca799414f (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
'use strict'

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

/* GET home page. */
router.get(['/', '/s/*', '/t/*', '/r/*', '/c/*'], function (req, res, next) {
  getMeetingpointData().then(data => {
    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(data.users)};`
    const validWeekNumbersStr = `var VALID_WEEK_NUMBERS = ${JSON.stringify(data.validWeekNumbers)}`

    res.render('index', { flagsStr, usersStr, validWeekNumbersStr })
  }).catch(function () {
    console.error('Unable to get user info, emergency redirect!')
    res.render('redirect')
  })
})

module.exports = router