'use strict'

var passport = require('passport')

module.exports = function(app) {
  var house = require('../controllers/houseController')

  app.route('/houses')
    .get(house.list_all_houses)
    .post(passport.authenticate('jwt', {
        session: false
      }),
      function(req, res) {
        var token = getToken(req.headers)
        if (token) {
          console.log("Creates a house: " + req.user)
          house.create_a_house(req, res)
        } else {
          return res.status(403).send({
            success: false,
            message: 'Unauthorized.'
          })
        }
      })

  app.route('/houses/:houseId')
    .get(house.read_a_house)
    .put(house.update_a_house)
    .delete(house.delete_a_house)
}

const getToken = (headers) => {
  if (headers && headers.authorization) {
    var parted = headers.authorization.split(' ')
    if (parted.length === 2) {
      return parted[1]
    } else {
      return null
    }
  } else {
    return null
  }
}

@@ -132,29 +132,97 @@
 oller')%0A
-%0A  app.route(
+  var versioning = require('../config/versioning')%0A%0A  app.route(versioning.url + 
 '/houses
@@ -434,41 +434,32 @@
     
-console.log(%22Creates a house: %22 +
+// User from token is at
  req
@@ -463,17 +463,16 @@
 req.user
-)
 %0A       
@@ -672,16 +672,33 @@
 p.route(
+versioning.url + 
 '/houses
@@ -806,16 +806,70 @@
 use)%0A%7D%0A%0A
+// JWT approach of getting token from request headers%0A
 const ge

Add API versioning for House endpoints.