{"size": 678, "ext": "js", "max_stars_repo_path": "src/reload.js", "max_stars_repo_name": "voorhoede/voorhoede-colibri-api", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/reload.js", "max_issues_repo_name": "voorhoede/voorhoede-colibri-api", "max_issues_repo_issues_event_min_datetime": "2018-03-13T19:53:37.000Z", "max_issues_repo_issues_event_max_datetime": "2018-04-03T19:09:07.000Z", "max_forks_repo_path": "src/reload.js", "max_forks_repo_name": "jbmoelker/voorhoede-colibri-api", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 16, "max_forks_count": null, "avg_line_length": 27.12, "max_line_length": 83, "alphanum_fraction": 0.6327433628}
require('dotenv').config()
const dataLoader = require('./data-loader')
const express = require('express')

const reloadToken = process.env.RELOAD_TOKEN
const router = express.Router()

router.post('/:token', (req, res) => {
  if (reloadToken && reloadToken === req.params.token) {
    dataLoader.reload()
    .then(newData => {
      res.json({ status: 'Data reloaded.' })
      console.log('Data reloaded.')
    })
    .catch(error => {
      res.status(500).json({ status: 'Error loading data.', error: error.message })
      console.error('Error reloading data', error)
    })
  } else {
    res.status(401).json({ status: 'Invalid token.' })
  }
})

module.exports = router
