{"size": 990, "ext": "js", "max_stars_repo_path": "server/data.js", "max_stars_repo_name": "egendata/example-cv-search", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "server/data.js", "max_issues_repo_name": "egendata/example-cv-search", "max_issues_repo_issues_event_min_datetime": "2020-01-24T12:38:59.000Z", "max_issues_repo_issues_event_max_datetime": "2020-01-24T12:38:59.000Z", "max_forks_repo_path": "server/data.js", "max_forks_repo_name": "egendata/example-cv-search", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 31.935483871, "max_line_length": 90, "alphanum_fraction": 0.6707070707}
const { Router } = require('express')
const router = Router()
const operator = require('./operatorClient')
const domain = operator.config.operator

router.use((req, res, next) => {
  const token = req.headers.authorization && req.headers.authorization.split('Bearer ')[1]
  if (!token) return next(Error('Invalid authorization header'))
  req.accessToken = token
  next()
})

router.get('/:area?', async ({ accessToken, params: { area } }, res, next) => {
  console.log('reading data from', domain, area, accessToken)
  try {
    const data = await operator.data.auth(accessToken).read({ domain, area })
    res.send(data)
  } catch (err) {
    console.error('get data error', area, err)
    console.log('data', JSON.stringify(err.response.data, null, 2))
  }
})

router.post('/:area', async ({ accessToken, body, params: { area } }, res, next) => {
  const data = body
  await operator.data.auth(accessToken).write({ domain, area, data })
  res.sendStatus(201)
})

module.exports = router
