diff --git a/api/server.js b/api/server.js new file mode 100644 index 00000000..2df9d52f --- /dev/null +++ b/api/server.js @@ -0,0 +1,33 @@ +// if you want to run the Just the API server without front-end run this file +var Hapi = require('hapi'); +var Basic = require('hapi-auth-basic'); +var AuthJWT = require('hapi-auth-jwt2') +var Joi = require('joi'); +var lout = require('lout'); +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(); + +server.connection({ port: port }); + +var routes = require('./routes.js'); + +server.register([ {register: Basic}, {register: AuthJWT}, { register: lout } ], function (err) { + + server.auth.strategy('basic', 'basic', { + validateFunc: require('./lib/auth_basic_validate.js') + }); + + server.auth.strategy('jwt', 'jwt', 'required', { + key: process.env.JWT_SECRET, + validateFunc: require('./lib/auth_jwt_validate.js') + }); + + server.route(routes); + +}); + +server.start(); +console.log('Now Visit: http://localhost:'+port); + +module.exports = server; diff --git a/app.js b/app.js index 36a050cb..11b43bf9 100644 --- a/app.js +++ b/app.js @@ -25,8 +25,7 @@ server.register([ {register: Basic}, {register: AuthJWT} ], function (err) { }); -server.start(function() { - console.log('Now Visit: http://localhost:'+port); -}); +server.start(); +console.log('Now Visit: http://localhost:'+port); module.exports = server; diff --git a/package.json b/package.json index b94e56c0..72c4b8c0 100644 --- a/package.json +++ b/package.json @@ -1,16 +1,16 @@ { "name": "atimer", - "version": "0.1.2", + "version": "0.1.3", "description": "Track any time-based activity", "main": "index.js", "scripts": { + "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 .", "start": "node app.js", "test": "node ./node_modules/tape/bin/tape ./api/test/*.js | node_modules/tap-spec/bin/cmd.js", "spec": "node ./node_modules/tape/bin/tape ./api/test/*.js | node_modules/tap-spec/bin/cmd.js" - }, "repository": { "type": "git", @@ -31,13 +31,14 @@ "aguid": "^1.0.3", "bcrypt": "^0.8.1", "boom": "^2.6.1", - "esta": "^3.0.1", + "esta": "^3.2.0", "hapi": "^8.2.0", "hapi-auth-basic": "^2.0.0", "hapi-auth-jwt2": "^3.2.1", "hoek": "^2.11.0", "joi": "^6.0.0", "jsonwebtoken": "^4.1.0", + "lout": "^6.2.1", "perma": "^2.0.1" }, "devDependencies": {