text: require('dotenv').config();
  
  const bcrypt = require('bcrypt');
  const knex = require('knex');
  const knexConfig = require('../knexfile');
  const db = knex(knexConfig.development);
  const jwt = require('jsonwebtoken');
  
  module.exports = server => {
    server.post('/api/register', register);
  };
  
  function generateToken(user) {
    const payload = {
      username: user.username
    };
    const secret = process.env.JWT_SECRET;
    const options = {
      expiresIn: '600m'
    };
    return jwt.sign(payload, secret, options);
  }
  
  function register(req, res) {
    const userInfo = req.body;
    const hash = bcrypt.hashSync(userInfo.password, 12);
    userInfo.password = hash;
    db('users')
      .insert(userInfo)
      .then(ids => {
        res.status(201).json(ids);
      })
      .catch(err => res.status(500).json(err));
  }
  