├── .gitignore ├── .npmignore ├── .travis.yml ├── Gruntfile.coffee ├── README.md ├── lib ├── i18n.js ├── i18n.js.map ├── index.js ├── index.js.map ├── routes-status-get.js └── routes-status-get.js.map ├── package.json ├── src ├── i18n.coffee ├── index.coffee └── routes-status-get.coffee └── test ├── index-tests.coffee ├── mocha.opts ├── routes-status-get-tests.coffee └── support └── load-server.coffee /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | config.json 3 | tmp 4 | public/assets 5 | *.log 6 | .DS_Store 7 | *.swp 8 | *.swo 9 | keys.txt 10 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | config.json 3 | tmp 4 | *.log 5 | .DS_Store 6 | *.swp 7 | *.swo 8 | assets-src 9 | assets-raw 10 | bower_components 11 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "0.10" 4 | -------------------------------------------------------------------------------- /Gruntfile.coffee: -------------------------------------------------------------------------------- 1 | _ = require 'underscore' 2 | 3 | coffeeRename = (destBase, destPath) -> 4 | destPath = destPath.replace 'src/','' 5 | destBase + destPath.replace /\.coffee$/, '.js' 6 | 7 | module.exports = (grunt) -> 8 | 9 | filterGrunt = -> 10 | gruntFiles = require("matchdep").filterDev("grunt-*") 11 | _.reject gruntFiles, (x) -> x is 'grunt-cli' 12 | 13 | filterGrunt().forEach grunt.loadNpmTasks 14 | 15 | config = 16 | coffee: 17 | compile: 18 | options: 19 | sourceMap: true 20 | files: grunt.file.expandMapping(['src/**/*.coffee'], 'lib/', {rename: coffeeRename }) 21 | 22 | shell: 23 | options: 24 | stdout: true 25 | npm_install: 26 | command: "npm install" 27 | 28 | env: 29 | test: 30 | NODE_ENV: "test" 31 | 32 | release: {} 33 | 34 | mochaTest: 35 | test: 36 | options: 37 | reporter: 'spec' 38 | require: 'coffee-script/register' 39 | src: ['test/**/*-tests.coffee'] 40 | mochacov: 41 | options: 42 | coveralls: 43 | repoToken: "Sr3UIg0e9vGOm8E8XVbAzzUWNk788tmBt" 44 | require: ['coffee-script/register','should'] 45 | all: ['test/**/*-tests.coffee'] 46 | 47 | config.watch = 48 | scripts: 49 | files: ['src/**/*.coffee'] 50 | tasks: ['build'] 51 | options: 52 | livereload: false 53 | 54 | tests: 55 | files: ['test/**/*.coffee'] 56 | tasks: ['build'] 57 | options: 58 | livereload: false 59 | 60 | grunt.initConfig config 61 | 62 | grunt.registerTask "install", [ 63 | "shell:npm_install" 64 | ] 65 | 66 | grunt.registerTask "build", [ 67 | 'coffee' 68 | 'test' 69 | ] 70 | 71 | grunt.registerTask "test", [ 72 | 'env:test' 73 | 'mochaTest:test' 74 | ] 75 | 76 | grunt.registerTask "testandcoverage", [ 77 | 'env:test' 78 | 'mochaTest:test' 79 | 'mochacov' 80 | ] 81 | 82 | grunt.registerTask 'deploy', [ 83 | 'test' 84 | 'release' 85 | ] 86 | 87 | grunt.registerTask 'default', ['build', 'watch'] 88 | 89 | 90 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/codedoctor/hapi-routes-status.svg?branch=master)](https://travis-ci.org/codedoctor/hapi-routes-status) 2 | [![Coverage Status](https://img.shields.io/coveralls/codedoctor/hapi-routes-status.svg)](https://coveralls.io/r/codedoctor/hapi-routes-status) 3 | [![NPM Version](http://img.shields.io/npm/v/hapi-routes-status.svg)](https://www.npmjs.org/package/hapi-routes-status) 4 | [![Dependency Status](https://gemnasium.com/codedoctor/hapi-routes-status.svg)](https://gemnasium.com/codedoctor/hapi-routes-status) 5 | [![NPM Downloads](http://img.shields.io/npm/dm/hapi-routes-status.svg)](https://www.npmjs.org/package/hapi-routes-status) 6 | [![Issues](http://img.shields.io/github/issues/codedoctor/hapi-routes-status.svg)](https://github.com/codedoctor/hapi-routes-status/issues) 7 | [![HAPI 8.0](http://img.shields.io/badge/hapi-8.0-blue.svg)](http://hapijs.com) 8 | [![API Documentation](http://img.shields.io/badge/API-Documentation-ff69b4.svg)](http://coffeedoc.info/github/codedoctor/hapi-routes-status) 9 | 10 | (C) 2014 Martin Wawrusch 11 | 12 | NOTE: For hapi < 8 use version 1.0.x 13 | 14 | Exposes a /status route which returns a json object similar to this: 15 | 16 | ```json 17 | { 18 | running: true, 19 | uptime: 12, 20 | memoryUsage: { 21 | rss: 57384960, 22 | heapTotal: 56160000, 23 | heapUsed: 19359568 24 | }, 25 | versions: { 26 | http_parser: "1.0", 27 | node: "0.10.22", 28 | v8: "3.14.5.9", 29 | ares: "1.9.0-DEV", 30 | uv: "0.10.19", 31 | zlib: "1.2.3", 32 | modules: "11", 33 | openssl: "1.0.1e" 34 | }, 35 | droneId: 41309 36 | } 37 | ``` 38 | 39 | ## See also 40 | 41 | * [hapi-auth-bearer-mw](https://github.com/codedoctor/hapi-auth-bearer-mw) 42 | * [hapi-loggly](https://github.com/codedoctor/hapi-loggly) 43 | * [hapi-mandrill](https://github.com/codedoctor/hapi-mandrill) 44 | * [hapi-mongoose-db-connector](https://github.com/codedoctor/hapi-mongoose-db-connector) 45 | * [hapi-oauth-store-multi-tenant](https://github.com/codedoctor/hapi-oauth-store-multi-tenant) 46 | * [hapi-routes-authorization-and-session-management](https://github.com/codedoctor/hapi-routes-authorization-and-session-management) 47 | * [hapi-routes-oauth-management](https://github.com/codedoctor/hapi-routes-oauth-management) 48 | * [hapi-routes-roles](https://github.com/codedoctor/hapi-routes-roles) 49 | * [hapi-routes-status](https://github.com/codedoctor/hapi-routes-status) 50 | * [hapi-routes-users-authorizations](https://github.com/codedoctor/hapi-routes-users-authorizations) 51 | * [hapi-routes-users](https://github.com/codedoctor/hapi-routes-users) 52 | * [hapi-user-store-multi-tenant](https://github.com/codedoctor/hapi-user-store-multi-tenant) 53 | 54 | and additionally 55 | 56 | * [api-pagination](https://github.com/codedoctor/api-pagination) 57 | * [mongoose-oauth-store-multi-tenant](https://github.com/codedoctor/mongoose-oauth-store-multi-tenant) 58 | * [mongoose-rest-helper](https://github.com/codedoctor/mongoose-rest-helper) 59 | * [mongoose-user-store-multi-tenant](https://github.com/codedoctor/mongoose-user-store-multi-tenant) 60 | 61 | ## Contributing 62 | 63 | * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet 64 | * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it 65 | * Fork the project 66 | * Start a feature/bugfix branch 67 | * Commit and push until you are happy with your contribution 68 | * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally. 69 | * Please try not to mess with the package.json, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it. 70 | 71 | ## Copyright 72 | 73 | Copyright (c) 2014 Martin Wawrusch 74 | -------------------------------------------------------------------------------- /lib/i18n.js: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Human readable messages used in the plugin. 4 | */ 5 | 6 | (function() { 7 | module.exports = { 8 | 9 | /* 10 | Do not translate 11 | */ 12 | optionsRouteTagsPublicRequiredAndArray: "options parameter requires a 'routesTagsPublic' field that is an array.", 13 | routeDescriptionStatusGet: "Returns the current status of the drone running this server instance." 14 | }; 15 | 16 | }).call(this); 17 | 18 | //# sourceMappingURL=i18n.js.map 19 | -------------------------------------------------------------------------------- /lib/i18n.js.map: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "file": "i18n.js", 4 | "sourceRoot": "../src/", 5 | "sources": [ 6 | "i18n.coffee" 7 | ], 8 | "names": [], 9 | "mappings": ";AACA;;;;AAAA;EAGA,MAAM,CAAC,OAAP,GACE;;AAAA;;;IAGA,sCAAA,EAAwC,yEAHxC;IAIA,yBAAA,EAA2B,uEAJ3B;;AAJF" 10 | } -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var Hoek, i18n, routesToExpose; 3 | 4 | Hoek = require('hoek'); 5 | 6 | i18n = require('./i18n'); 7 | 8 | routesToExpose = [require('./routes-status-get')]; 9 | 10 | module.exports.register = function(server, options, cb) { 11 | var defaults, i, len, r; 12 | if (options == null) { 13 | options = {}; 14 | } 15 | defaults = { 16 | routeTagsPublic: ['api', 'api-public', 'status'], 17 | routeTagsAdmin: ['api', 'api-admin', 'status'] 18 | }; 19 | options = Hoek.applyToDefaults(defaults, options); 20 | for (i = 0, len = routesToExpose.length; i < len; i++) { 21 | r = routesToExpose[i]; 22 | r(server, options); 23 | } 24 | server.expose('i18n', i18n); 25 | return cb(); 26 | }; 27 | 28 | module.exports.register.attributes = { 29 | pkg: require('../package.json') 30 | }; 31 | 32 | }).call(this); 33 | 34 | //# sourceMappingURL=index.js.map 35 | -------------------------------------------------------------------------------- /lib/index.js.map: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "file": "index.js", 4 | "sourceRoot": "../src/", 5 | "sources": [ 6 | "index.coffee" 7 | ], 8 | "names": [], 9 | "mappings": "AAAA;AAAA,MAAA;;EAAA,IAAA,GAAO,OAAA,CAAQ,MAAR;;EACP,IAAA,GAAO,OAAA,CAAQ,QAAR;;EAEP,cAAA,GAAiB,CACf,OAAA,CAAQ,qBAAR,CADe;;EAKjB,MAAM,CAAC,OAAO,CAAC,QAAf,GAA0B,SAAC,MAAD,EAAS,OAAT,EAAuB,EAAvB;AAExB,QAAA;;MAFiC,UAAU;;IAE3C,QAAA,GACE;MAAA,eAAA,EAAiB,CAAC,KAAD,EAAO,YAAP,EAAoB,QAApB,CAAjB;MACA,cAAA,EAAgB,CAAC,KAAD,EAAO,WAAP,EAAmB,QAAnB,CADhB;;IAGF,OAAA,GAAU,IAAI,CAAC,eAAL,CAAqB,QAArB,EAA+B,OAA/B;AAEV,SAAA,gDAAA;;MAAA,CAAA,CAAE,MAAF,EAAS,OAAT;AAAA;IAEA,MAAM,CAAC,MAAP,CAAc,MAAd,EAAqB,IAArB;WAEA,EAAA,CAAA;EAZwB;;EAc1B,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,UAAxB,GACE;IAAA,GAAA,EAAK,OAAA,CAAQ,iBAAR,CAAL;;AAvBF" 10 | } -------------------------------------------------------------------------------- /lib/routes-status-get.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var Hoek, Joi, _, i18n; 3 | 4 | _ = require('underscore'); 5 | 6 | Hoek = require('hoek'); 7 | 8 | Joi = require('joi'); 9 | 10 | i18n = require('./i18n'); 11 | 12 | 13 | /* 14 | Returns the current status. Looks something like this: 15 | 16 | { 17 | "running":true, 18 | "uptime":1.964, 19 | "memoryUsage":{"rss":111693824,"heapTotal":86533888,"heapUsed":53585416}, 20 | "versions":{"http_parser":"2.3","node":"0.12.4","v8":"3.28.71.19","uv":"1.5.0","zlib":"1.2.8","modules":"14","openssl":"1.0.1m"}, 21 | "droneId":34247 22 | 23 | {"http_parser":"2.3","node":"0.12.4","v8":"3.28.71.19","uv":"1.5.0","zlib":"1.2.8","modules":"14","openssl":"1.0.1m"} 24 | } 25 | */ 26 | 27 | module.exports = function(plugin, options) { 28 | Hoek.assert(options.routeTagsPublic && _.isArray(options.routeTagsPublic), i18n.optionsRouteTagsPublicRequiredAndArray); 29 | return plugin.route({ 30 | path: '/status', 31 | method: 'GET', 32 | config: { 33 | description: i18n.routeDescriptionStatusGet, 34 | tags: options.routeTagsPublic, 35 | auth: false, 36 | response: { 37 | schema: Joi.object({ 38 | running: Joi.boolean()["default"](true).description("Indicates if the service is running.").example(true).required(), 39 | uptime: Joi.number().description("The uptime of this process.").example(1.2333).required(), 40 | memoryUsage: Joi.object().description("Detailed information about the memory usage.").example('{"rss":111693824,"heapTotal":86533888,"heapUsed":53585416}').required(), 41 | versions: Joi.object().description("System library version information.").example('{"http_parser":"2.3","node":"0.12.4","v8":"3.28.71.19","uv":"1.5.0","zlib":"1.2.8","modules":"14","openssl":"1.0.1m"}').required(), 42 | droneId: Joi.number().description("The id of the drone running this instance.").example(23453).required() 43 | }).description("The status result object.").required().options({ 44 | allowUnknown: true, 45 | stripUnknown: false 46 | }) 47 | } 48 | }, 49 | handler: function(request, reply) { 50 | return reply({ 51 | running: true, 52 | uptime: process.uptime(), 53 | memoryUsage: process.memoryUsage(), 54 | versions: process.versions, 55 | droneId: process.pid 56 | }); 57 | } 58 | }); 59 | }; 60 | 61 | }).call(this); 62 | 63 | //# sourceMappingURL=routes-status-get.js.map 64 | -------------------------------------------------------------------------------- /lib/routes-status-get.js.map: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "file": "routes-status-get.js", 4 | "sourceRoot": "../src/", 5 | "sources": [ 6 | "routes-status-get.coffee" 7 | ], 8 | "names": [], 9 | "mappings": "AAAA;AAAA,MAAA;;EAAA,CAAA,GAAI,OAAA,CAAQ,YAAR;;EACJ,IAAA,GAAO,OAAA,CAAQ,MAAR;;EACP,GAAA,GAAM,OAAA,CAAQ,KAAR;;EACN,IAAA,GAAO,OAAA,CAAQ,QAAR;;;AAEP;;;;;;;;;;;;;;EAcA,MAAM,CAAC,OAAP,GAAiB,SAAC,MAAD,EAAQ,OAAR;IACf,IAAI,CAAC,MAAL,CAAY,OAAO,CAAC,eAAR,IAA2B,CAAC,CAAC,OAAF,CAAU,OAAO,CAAC,eAAlB,CAAvC,EAA0E,IAAI,CAAC,sCAA/E;WAEA,MAAM,CAAC,KAAP,CACE;MAAA,IAAA,EAAM,SAAN;MACA,MAAA,EAAQ,KADR;MAEA,MAAA,EACE;QAAA,WAAA,EAAa,IAAI,CAAC,yBAAlB;QACA,IAAA,EAAM,OAAO,CAAC,eADd;QAEA,IAAA,EAAM,KAFN;QAGA,QAAA,EACE;UAAA,MAAA,EAAQ,GAAG,CAAC,MAAJ,CACM;YAAA,OAAA,EAAS,GAAG,CAAC,OAAJ,CAAA,CAAa,CAAC,SAAD,CAAb,CAAsB,IAAtB,CAA2B,CAAC,WAA5B,CAAwC,sCAAxC,CAA+E,CAAC,OAAhF,CAAwF,IAAxF,CAA6F,CAAC,QAA9F,CAAA,CAAT;YACA,MAAA,EAAQ,GAAG,CAAC,MAAJ,CAAA,CAAY,CAAC,WAAb,CAAyB,6BAAzB,CAAuD,CAAC,OAAxD,CAAgE,MAAhE,CAAuE,CAAC,QAAxE,CAAA,CADR;YAEA,WAAA,EAAa,GAAG,CAAC,MAAJ,CAAA,CAAY,CAAC,WAAb,CAAyB,8CAAzB,CAAwE,CAAC,OAAzE,CAAiF,4DAAjF,CAA8I,CAAC,QAA/I,CAAA,CAFb;YAGA,QAAA,EAAU,GAAG,CAAC,MAAJ,CAAA,CAAY,CAAC,WAAb,CAAyB,qCAAzB,CAA+D,CAAC,OAAhE,CAAwE,uHAAxE,CAAgM,CAAC,QAAjM,CAAA,CAHV;YAIA,OAAA,EAAS,GAAG,CAAC,MAAJ,CAAA,CAAY,CAAC,WAAb,CAAyB,4CAAzB,CAAsE,CAAC,OAAvE,CAA+E,KAA/E,CAAqF,CAAC,QAAtF,CAAA,CAJT;WADN,CAMG,CAAC,WANJ,CAMgB,2BANhB,CAM4C,CAAC,QAN7C,CAAA,CAMuD,CAAC,OANxD,CAMgE;YAAC,YAAA,EAAc,IAAf;YAAoB,YAAA,EAAc,KAAlC;WANhE,CAAR;SAJF;OAHF;MAeA,OAAA,EAAS,SAAC,OAAD,EAAU,KAAV;eACP,KAAA,CACE;UAAA,OAAA,EAAS,IAAT;UACA,MAAA,EAAQ,OAAO,CAAC,MAAR,CAAA,CADR;UAEA,WAAA,EAAa,OAAO,CAAC,WAAR,CAAA,CAFb;UAGA,QAAA,EAAU,OAAO,CAAC,QAHlB;UAIA,OAAA,EAAS,OAAO,CAAC,GAJjB;SADF;MADO,CAfT;KADF;EAHe;AAnBjB" 10 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hapi-routes-status", 3 | "version": "2.1.1", 4 | "private": false, 5 | "main": "lib/index.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/codedoctor/hapi-routes-status.git" 9 | }, 10 | "engines": { 11 | "node": "0.10.x" 12 | }, 13 | "scripts": { 14 | "test": "node_modules/.bin/grunt testandcoverage" 15 | }, 16 | "description": "Exposes a /status endpoint", 17 | "dependencies": { 18 | "hoek": "2.14.0", 19 | "boom": "2.8.0", 20 | "joi": "6.6.1", 21 | "underscore": "1.8.3" 22 | }, 23 | "peerDependencies": { 24 | "hapi": ">=8.0.0" 25 | }, 26 | "devDependencies": { 27 | "blanket": "1.1.7", 28 | "codo": "2.0.11", 29 | "coffee-script": "1.9.3", 30 | "deep-equal": "1.0.0", 31 | "grunt": "0.4.5", 32 | "grunt-cli": "0.1.13", 33 | "grunt-concurrent": "2.0.1", 34 | "grunt-contrib-coffee": "0.13.0", 35 | "grunt-contrib-watch": "0.6.1", 36 | "grunt-env": "0.4.4", 37 | "grunt-mocha-cov": "0.4.0", 38 | "grunt-mocha-test": "0.12.7", 39 | "grunt-release": "0.13.0", 40 | "grunt-shell": "1.1.2", 41 | "hapi": "8.8.1", 42 | "matchdep": "0.3.0", 43 | "mocha": "2.2.5", 44 | "should": "7.0.3" 45 | }, 46 | "config": { 47 | "blanket": { 48 | "pattern": [ 49 | "lib" 50 | ], 51 | "data-cover-never": "node_modules" 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/i18n.coffee: -------------------------------------------------------------------------------- 1 | 2 | ### 3 | Human readable messages used in the plugin. 4 | ### 5 | module.exports = 6 | ### 7 | Do not translate 8 | ### 9 | optionsRouteTagsPublicRequiredAndArray: "options parameter requires a 'routesTagsPublic' field that is an array." 10 | routeDescriptionStatusGet: "Returns the current status of the drone running this server instance." 11 | -------------------------------------------------------------------------------- /src/index.coffee: -------------------------------------------------------------------------------- 1 | Hoek = require 'hoek' 2 | i18n = require './i18n' 3 | 4 | routesToExpose = [ 5 | require './routes-status-get' 6 | ] 7 | 8 | 9 | module.exports.register = (server, options = {}, cb) -> 10 | 11 | defaults = 12 | routeTagsPublic: ['api','api-public','status'] 13 | routeTagsAdmin: ['api','api-admin','status'] 14 | 15 | options = Hoek.applyToDefaults defaults, options 16 | 17 | r server,options for r in routesToExpose 18 | 19 | server.expose 'i18n',i18n 20 | 21 | cb() 22 | 23 | module.exports.register.attributes = 24 | pkg: require '../package.json' 25 | 26 | -------------------------------------------------------------------------------- /src/routes-status-get.coffee: -------------------------------------------------------------------------------- 1 | _ = require 'underscore' 2 | Hoek = require 'hoek' 3 | Joi = require 'joi' 4 | i18n = require './i18n' 5 | 6 | ### 7 | Returns the current status. Looks something like this: 8 | 9 | { 10 | "running":true, 11 | "uptime":1.964, 12 | "memoryUsage":{"rss":111693824,"heapTotal":86533888,"heapUsed":53585416}, 13 | "versions":{"http_parser":"2.3","node":"0.12.4","v8":"3.28.71.19","uv":"1.5.0","zlib":"1.2.8","modules":"14","openssl":"1.0.1m"}, 14 | "droneId":34247 15 | 16 | {"http_parser":"2.3","node":"0.12.4","v8":"3.28.71.19","uv":"1.5.0","zlib":"1.2.8","modules":"14","openssl":"1.0.1m"} 17 | } 18 | 19 | ### 20 | module.exports = (plugin,options) -> 21 | Hoek.assert options.routeTagsPublic && _.isArray(options.routeTagsPublic),i18n.optionsRouteTagsPublicRequiredAndArray 22 | 23 | plugin.route 24 | path: '/status' 25 | method: 'GET' 26 | config: 27 | description: i18n.routeDescriptionStatusGet 28 | tags: options.routeTagsPublic 29 | auth: false 30 | response: 31 | schema: Joi.object( 32 | running: Joi.boolean().default(true).description("Indicates if the service is running.").example(true).required() 33 | uptime: Joi.number().description("The uptime of this process.").example(1.2333).required() 34 | memoryUsage: Joi.object().description("Detailed information about the memory usage.").example('{"rss":111693824,"heapTotal":86533888,"heapUsed":53585416}').required() 35 | versions: Joi.object().description("System library version information.").example('{"http_parser":"2.3","node":"0.12.4","v8":"3.28.71.19","uv":"1.5.0","zlib":"1.2.8","modules":"14","openssl":"1.0.1m"}').required() 36 | droneId: Joi.number().description("The id of the drone running this instance.").example(23453).required() 37 | ).description("The status result object.").required().options({allowUnknown: true,stripUnknown: false}) 38 | 39 | handler: (request, reply) -> 40 | reply 41 | running: true 42 | uptime: process.uptime() 43 | memoryUsage: process.memoryUsage() 44 | versions: process.versions 45 | droneId: process.pid 46 | 47 | 48 | -------------------------------------------------------------------------------- /test/index-tests.coffee: -------------------------------------------------------------------------------- 1 | assert = require 'assert' 2 | should = require 'should' 3 | index = require '../lib/index' 4 | _ = require 'underscore' 5 | 6 | loadServer = require './support/load-server' 7 | 8 | describe 'WHEN index has been loaded', -> 9 | it 'it should expose a HAPI interface', (cb) -> 10 | 11 | should.exist index 12 | index.should.have.property "register" 13 | index.register.should.have.property "attributes" 14 | 15 | cb null 16 | 17 | it 'it should load the plugin', (cb) -> 18 | loadServer (err,server) -> 19 | return cb err if err 20 | 21 | should.exist server 22 | should.exist server.plugins['hapi-routes-status'] 23 | 24 | cb null 25 | -------------------------------------------------------------------------------- /test/mocha.opts: -------------------------------------------------------------------------------- 1 | --require assert 2 | --require should 3 | --globals name,adminApp,skindb,i,len,asset 4 | --compilers coffee:coffee-script/register -------------------------------------------------------------------------------- /test/routes-status-get-tests.coffee: -------------------------------------------------------------------------------- 1 | assert = require 'assert' 2 | should = require 'should' 3 | 4 | loadServer = require './support/load-server' 5 | 6 | describe 'WHEN route testing for status-routes', -> 7 | describe '/status', -> 8 | loadServer (err,server) -> 9 | return cb err if err 10 | it 'should respond with an up status', (cb) -> 11 | options = 12 | method: "GET" 13 | url: "/status" 14 | 15 | server.inject options, (response) -> 16 | result = response.result 17 | 18 | response.statusCode.should.equal 200 19 | should.exist result 20 | 21 | result.should.have.property 'running',true 22 | result.should.have.property 'uptime' 23 | result.should.have.property 'memoryUsage' 24 | 25 | cb null 26 | -------------------------------------------------------------------------------- /test/support/load-server.coffee: -------------------------------------------------------------------------------- 1 | index = require '../../lib/index' 2 | Hapi = require "hapi" 3 | _ = require 'underscore' 4 | 5 | module.exports = loadServer = (cb) -> 6 | server = new Hapi.Server() 7 | 8 | server.connection 9 | host: 'localhost' 10 | port: 5675 11 | 12 | pluginConf = [ 13 | register: index 14 | ] 15 | 16 | server.register pluginConf, (err) -> 17 | cb err,server --------------------------------------------------------------------------------