const express = require('express');
const allow = require('../middleware/allow');

const router = new express.Router();

router.get(/\/(?!admin_).*/, (req, res) => {
  res.render('index', {
    title: '夜半编码',
    role: req.user ? req.user.role : 'user',
    name: req.user ? req.user.name : '',
    statu: req.user ? 'logout' : 'login',
  });
});

router.get(/\/admin_.*/, allow('admin'), (req, res) => {
  res.render('index', {
    title: '夜半编码',
    role: req.user ? req.user.role : 'user',
    name: req.user ? req.user.name : '',
    statu: req.user ? 'logout' : 'login',
  });
});

module.exports = router;
