diff --git a/api/handlers/timer_start.js b/api/handlers/timer_start.js index 10876c78..b1e833e6 100644 --- a/api/handlers/timer_start.js +++ b/api/handlers/timer_start.js @@ -14,15 +14,15 @@ module.exports = function(req, reply) { type: "timer", person: decoded.person, session: decoded.jti, // session id from JWT - ct: created, + created: created, id: id } for (var k in req.payload){ timer[k] = req.payload[k]; // extract values from payload } - if(!timer.st) { // client did not define the start time - timer.st = created; // set it to the same as created + if(!timer.start) { // client did not define the start time + timer.start = created; // set it to the same as created } else { // allow the client to set the started time } diff --git a/api/lib/auth_jwt_validate.js b/api/lib/auth_jwt_validate.js index f0cdf944..477ec5e5 100644 --- a/api/lib/auth_jwt_validate.js +++ b/api/lib/auth_jwt_validate.js @@ -1,4 +1,4 @@ -var ES = require('esta'); +var ES = require('esta'); var validateFunc = function (decoded, request, callback) { diff --git a/api/routes.js b/api/routes.js index ff2ba2d4..b8c45bf7 100644 --- a/api/routes.js +++ b/api/routes.js @@ -1,10 +1,4 @@ module.exports = [ - { path: '/', method: 'GET', - config: { - auth: false, - handler: require('./handlers/home') - } - }, { path: '/anonymous', method: 'GET', config: { auth: false, handler: require('./handlers/anonymous.js') } }, { path: '/register', method: 'POST', diff --git a/api/test/anonymous.js b/api/test/anonymous.js index af5ff892..66267a7b 100644 --- a/api/test/anonymous.js +++ b/api/test/anonymous.js @@ -24,7 +24,7 @@ test(file + "Anonymous people can create timers!", function(t) { var token = res.headers.authorization; var timer = { "desc" : "Anonymous people deserve a voice too!", - "st" : new Date().toISOString() + "start" : new Date().toISOString() } var options = { method: "POST", diff --git a/api/test/timer_find_all.js b/api/test/timer_find_all.js index b9865dac..707e9493 100644 --- a/api/test/timer_find_all.js +++ b/api/test/timer_find_all.js @@ -17,7 +17,7 @@ test(file+ "Teardown", function(t) { function create(t, callback) { var timer = { "desc" : "My Amazing Timer #"+countdown, - "st" : new Date().toISOString() + "start" : new Date().toISOString() } var options = { method: "POST", @@ -53,9 +53,6 @@ function finish(res, t){ }); } - - -// new anonymous person test(file + "Register new person to create a few timers", function(t) { var person = { "email" : "multiple.timers@awesome.net", @@ -98,8 +95,7 @@ test(file + "GET /timer/all to list all timers", function(t) { test(file + "GET /timer/all should fail for Timmy no timers", function(t) { var person = { "email" : "timmy.no.timers@awesome.net", - "password" : "EveryThingisAwesome", - "firstname": "Timmay!" + "password" : "EveryThingisAwesome" } var options = { method : "POST", diff --git a/api/test/timer_start.js b/api/test/timer_start.js index a328a892..417573ab 100644 --- a/api/test/timer_start.js +++ b/api/test/timer_start.js @@ -72,7 +72,7 @@ test(file + "START a NEW Timer (no st sent by client)!", function(t) { test(file + "START a NEW Timer with start time!", function(t) { var timer = { "desc" : "We're going to Ibiza!", - "st" : new Date().toISOString() + "start" : new Date().toISOString() } var options = { method: "POST", diff --git a/front/handlers/home.js b/front/handlers/home.js new file mode 100644 index 00000000..c5ee229a --- /dev/null +++ b/front/handlers/home.js @@ -0,0 +1,3 @@ +module.exports = function(req, reply) { + reply('Welcome to Timer Land!'); // to be improved: http://git.io/pHTs +} diff --git a/front/routes.js b/front/routes.js new file mode 100644 index 00000000..804f894b --- /dev/null +++ b/front/routes.js @@ -0,0 +1,8 @@ +module.exports = [ + { path: '/', method: 'GET', + config: { + auth: false, + handler: require('./handlers/home') + } + } +] diff --git a/front/views/index.html b/front/views/index.html new file mode 100644 index 00000000..9c62b174 --- /dev/null +++ b/front/views/index.html @@ -0,0 +1,2 @@ +
{{fortune}}
diff --git a/front/views/partials/page.html b/front/views/partials/page.html new file mode 100644 index 00000000..e69de29b diff --git a/models/timer.js b/models/timer.js index 0234d1a8..cb9c437d 100644 --- a/models/timer.js +++ b/models/timer.js @@ -1,11 +1,11 @@ var Joi = require('joi'); module.exports = { payload: { - person: Joi.forbidden(), - desc: Joi.string().optional(), - ct: Joi.forbidden(), // don't allow people to set this! - st: Joi.date().iso(), - et: Joi.date().iso().optional(), - aid: Joi.string() + person: Joi.forbidden(), + desc: Joi.string().optional(), + created: Joi.forbidden(), // don't allow people to set this! + start: Joi.date().iso(), + end: Joi.date().iso().optional(), + aid: Joi.string() } } diff --git a/package.json b/package.json index 72c4b8c0..3e698928 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Track any time-based activity", "main": "index.js", "scripts": { - "api":"node ./api/server.js", + "api": "node ./api/server.js", "codeclimate": "CODECLIMATE_REPO_TOKEN=0839d00dd01047ffadfb3c56bf9c9baa0047179de582a47517e3f558ad4eafff ./node_modules/codeclimate-test-reporter/bin/codeclimate.js < ./coverage/lcov.info", "coverage": "./node_modules/.bin/istanbul cover ./node_modules/tape/bin/tape ./api/test/*.js | node_modules/tap-spec/bin/cmd.js && ./node_modules/.bin/istanbul check-coverage --statements 100 --functions 100 --lines 100 --branches 100", "jshint": "./node_modules/jshint/bin/jshint -c .jshintrc --exclude-path .gitignore .", @@ -32,6 +32,7 @@ "bcrypt": "^0.8.1", "boom": "^2.6.1", "esta": "^3.2.0", + "handlebars": "^3.0.0", "hapi": "^8.2.0", "hapi-auth-basic": "^2.0.0", "hapi-auth-jwt2": "^3.2.1", diff --git a/web.js b/web.js index b0b1fed3..f3e28bd5 100644 --- a/web.js +++ b/web.js @@ -1,15 +1,14 @@ var Hapi = require('hapi'); var Basic = require('hapi-auth-basic'); +var Hoek = require('hoek'); var AuthJWT = require('hapi-auth-jwt2') var Joi = require('joi'); var ES = require('esta'); // https://github.com/nelsonic/esta var port = process.env.PORT || 1337; // heroku define port or use 1337 var server = new Hapi.Server(); - +var Path = require('path'); server.connection({ port: port }); -var routes = require('./api/routes.js'); - server.register([ {register: Basic}, {register: AuthJWT} ], function (err) { server.auth.strategy('basic', 'basic', { @@ -21,6 +20,27 @@ server.register([ {register: Basic}, {register: AuthJWT} ], function (err) { validateFunc: require('./api/lib/auth_jwt_validate.js') }); + server.views({ + engines: { + html: require('handlebars') + }, + path: Path.join(__dirname, 'front/views') + }); + var api = require('./api/routes.js'); + // var front = require('./front/routes.js'); + var front = [{ + path: '/', + method: 'GET', + config: { + auth: false, + handler: function(request, reply) { + reply.view("index", {fortune:"everything is awesome"}); + } + } + }] + + var routes = Hoek.merge(api, front); + server.route(routes); });