Skip to content

Commit

Permalink
[WiP] basic handlebars view. nothing to see yet. #77
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonic committed Mar 15, 2015
1 parent 1622d3c commit d32add6
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 28 deletions.
6 changes: 3 additions & 3 deletions api/handlers/timer_start.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion api/lib/auth_jwt_validate.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var ES = require('esta');
var ES = require('esta');

var validateFunc = function (decoded, request, callback) {

Expand Down
6 changes: 0 additions & 6 deletions api/routes.js
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
2 changes: 1 addition & 1 deletion api/test/anonymous.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 2 additions & 6 deletions api/test/timer_find_all.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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" : "[email protected]",
Expand Down Expand Up @@ -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" : "[email protected]",
"password" : "EveryThingisAwesome",
"firstname": "Timmay!"
"password" : "EveryThingisAwesome"
}
var options = {
method : "POST",
Expand Down
2 changes: 1 addition & 1 deletion api/test/timer_start.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions front/handlers/home.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function(req, reply) {
reply('Welcome to Timer Land!'); // to be improved: http://git.io/pHTs
}
8 changes: 8 additions & 0 deletions front/routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = [
{ path: '/', method: 'GET',
config: {
auth: false,
handler: require('./handlers/home')
}
}
]
2 changes: 2 additions & 0 deletions front/views/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>Your fortune</h1>
<p>{{fortune}}</p>
Empty file added front/views/partials/page.html
Empty file.
12 changes: 6 additions & 6 deletions models/timer.js
Original file line number Diff line number Diff line change
@@ -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()
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 .",
Expand Down Expand Up @@ -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",
Expand Down
26 changes: 23 additions & 3 deletions web.js
Original file line number Diff line number Diff line change
@@ -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', {
Expand All @@ -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);

});
Expand Down

0 comments on commit d32add6

Please sign in to comment.