const express = require('express')
const app = express()
const config = require('config')    // https://github.com/lorenwest/node-config

const jwt = require('jsonwebtoken')
const bcrypt = require('bcryptjs')

var Animal = require('../share/entities/Animal')


app.set('port', process.env.PORT || 3000)


/* Create example data START */
var myPet01 = new Animal('Peter')
myPet01.age = 2

var myPet02 = new Animal('Cinemon')
myPet02.age = 4.6

var pets = [myPet01, myPet02]
/* Create example data END */


app.get('/', (req, res) => res.send('Hello world!'))

app.get('/animals/', function (req, res) {
  // create a token
  var token = jwt.sign(JSON.stringify(pets), config.get('secret'), {});
  console.log(token)
  res.json({token: token});
});

app.listen(app.get('port'), () => console.log('Service listening on port '+app.get('port')+'!'))