├── .gitignore ├── .travis.yml ├── examples ├── plain.js ├── custom.js └── full.js ├── package.json ├── lib └── index.js ├── LICENSE ├── README.md └── tests └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | coverage 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "0.10" 4 | - "0.12" 5 | - "4.5.0" 6 | - "6.6.0" 7 | -------------------------------------------------------------------------------- /examples/plain.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Yahoo! Inc. All rights reserved. 3 | * Copyrights licensed under the New BSD License. 4 | * See the accompanying LICENSE file for terms. 5 | */ 6 | 7 | var express = require('express'), 8 | status = require('../lib/index.js'); 9 | 10 | var app = express(); 11 | 12 | app.use(status()); 13 | 14 | console.log('Go to: http://127.0.0.1:8000/status.html'); 15 | app.listen(8000); 16 | -------------------------------------------------------------------------------- /examples/custom.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Yahoo! Inc. All rights reserved. 3 | * Copyrights licensed under the New BSD License. 4 | * See the accompanying LICENSE file for terms. 5 | */ 6 | 7 | var express = require('express'), 8 | status = require('../lib/index.js'); 9 | 10 | var app = express(); 11 | 12 | app.use(status({ 13 | url: '/status', 14 | text: 'This process looks ok' 15 | })); 16 | 17 | console.log('Go to: http://127.0.0.1:8000/status'); 18 | app.listen(8000); 19 | -------------------------------------------------------------------------------- /examples/full.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Yahoo! Inc. All rights reserved. 3 | * Copyrights licensed under the New BSD License. 4 | * See the accompanying LICENSE file for terms. 5 | */ 6 | 7 | var express = require('express'), 8 | status = require('../lib/index.js'); 9 | 10 | var app = express(); 11 | 12 | app.use(status({ 13 | url: '/status', 14 | version: true, 15 | uptime: true, 16 | check: function(req) { 17 | if (req.something == false) { 18 | return false; //Don't show status 19 | } 20 | return true; //Show status 21 | } 22 | })); 23 | 24 | console.log('Go to: http://127.0.0.1:8000/status'); 25 | app.listen(8000); 26 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mod_status", 3 | "description": "mod_status for Node", 4 | "author": "Dav Glass ", 5 | "version": "1.0.0", 6 | "dependencies": { 7 | "timethat": "*" 8 | }, 9 | "devDependencies": { 10 | "express": "^4.16.4", 11 | "istanbul": "^0.4.5", 12 | "jshint": "^2.9.6", 13 | "vows": "*", 14 | "yui-lint": "^0.2.0" 15 | }, 16 | "keywords": [ 17 | "mod_status", 18 | "status", 19 | "nagios" 20 | ], 21 | "main": "./lib/index.js", 22 | "scripts": { 23 | "pretest": "jshint --config ./node_modules/yui-lint/jshint.json ./lib/ ./tests/", 24 | "test": "istanbul cover --print both vows -- --spec ./tests/*.js" 25 | }, 26 | "bugs": { 27 | "url": "http://github.com/yahoo/node-mod_status/issues" 28 | }, 29 | "licenses": [ 30 | { 31 | "type": "BSD", 32 | "url": "https://github.com/yahoo/node-mod_status/blob/master/LICENSE" 33 | } 34 | ], 35 | "repository": { 36 | "type": "git", 37 | "url": "http://github.com/yahoo/node-mod_status.git" 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Yahoo! Inc. All rights reserved. 3 | * Copyrights licensed under the New BSD License. 4 | * See the accompanying LICENSE file for terms. 5 | */ 6 | 7 | var url = require('url'), 8 | timethat = require('timethat'); 9 | 10 | module.exports = function(config) { 11 | config = config || {}; 12 | config.url = config.url || '/status.html'; 13 | return function mod_status(req, res, next) { 14 | var respond, 15 | responseText = config.text || 'OK'; 16 | if (!config.text) { 17 | if (config.version) { 18 | responseText += ' - Node: ' + process.version; 19 | } 20 | if (config.uptime) { 21 | responseText += ' - Uptime: ' + timethat.calc((new Date(Date.now() - (process.uptime() * 1000)))); 22 | } 23 | } 24 | req.parsedUrl = req.parsedUrl || url.parse(req.url, true); 25 | if (req.parsedUrl.pathname === config.url) { 26 | respond = (config.check) ? config.check(req) : true; 27 | if (respond) { 28 | res.writeHead(200, { 29 | 'Content-Type' : 'text/plain' 30 | }); 31 | res.end(responseText); 32 | } else { 33 | res.writeHead(404, { 34 | 'Content-Type' : 'text/plain' 35 | }); 36 | res.end('Not Found'); 37 | } 38 | } else { 39 | next(); 40 | } 41 | }; 42 | }; 43 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013, Yahoo! Inc. All rights reserved. 2 | 3 | Redistribution and use of this software in source and binary forms, 4 | with or without modification, are permitted provided that the following 5 | conditions are met: 6 | 7 | * Redistributions of source code must retain the above 8 | copyright notice, this list of conditions and the 9 | following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above 12 | copyright notice, this list of conditions and the 13 | following disclaimer in the documentation and/or other 14 | materials provided with the distribution. 15 | 16 | * Neither the name of Yahoo! Inc. nor the names of its 17 | contributors may be used to endorse or promote products 18 | derived from this software without specific prior 19 | written permission of Yahoo! Inc. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 22 | IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 23 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 24 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ARCHIVED 2 | 3 | 4 | mod_status for Node 5 | =================== 6 | 7 | Simple express/connect middleware to provide an "apache-like" `/status.html` page. 8 | 9 | Installation 10 | ------------ 11 | 12 | `npm install mod_status` 13 | 14 | Usage 15 | ----- 16 | 17 | ```javascript 18 | var express = require('express'), 19 | status = require('../lib/index.js'); 20 | 21 | var app = express(); 22 | 23 | app.use(status({ 24 | url: '/status', 25 | version: true, 26 | uptime: true, 27 | check: function(req) { 28 | if (req.something == false) { 29 | return false; //Don't show status 30 | } 31 | return true; //Show status 32 | } 33 | })); 34 | 35 | console.log('Go to: http://127.0.0.1:8000/status'); 36 | app.listen(8000); 37 | ``` 38 | 39 | Configuration 40 | ------------- 41 | 42 | * `url` - The URL to respond to, defaults to `/status.html` 43 | * `version` - Show the Node.js version in the output. Default: `false` 44 | * `uptime` - Show the uptime of the process in the output: Default: `false` 45 | * `text` - Provide custom response text, will override all the above. Default: `null` 46 | * `check` - A function to check the request to see if the status page should be shown. Default: `returns true to always show` 47 | 48 | Example Output 49 | -------------- 50 | 51 | * `OK` - Default 52 | * `OK - NodeJS: v0.10.17` - From `version: true` 53 | * `OK - Uptime: 2 days, 3 hours, 4 minutes` - From `uptime: true` 54 | * `OK - NodeJSL v0.10.17 - Uptime: 2 days, 3 hours, 4 minutes` - From `uptime: true & version: true` 55 | * `WORKS` - From `text: 'WORKS'` 56 | 57 | Build Status 58 | ------------ 59 | 60 | [![Build Status](https://secure.travis-ci.org/yahoo/node-mod_status.png?branch=master)](http://travis-ci.org/yahoo/node-mod_status) 61 | 62 | Node Badge 63 | ---------- 64 | 65 | [![NPM](https://nodei.co/npm/mod_status.png)](https://nodei.co/npm/mod_status/) 66 | 67 | -------------------------------------------------------------------------------- /tests/index.js: -------------------------------------------------------------------------------- 1 | var vows = require('vows'), 2 | assert = require('assert'), 3 | mod_status = require('../lib/index.js'); 4 | 5 | var tests = { 6 | 'loading': { 7 | topic: function() { 8 | return mod_status; 9 | }, 10 | 'should be a function': function(topic) { 11 | assert.isFunction(topic); 12 | }, 13 | 'and should return': { 14 | topic: function() { 15 | return mod_status(); 16 | }, 17 | 'a function': function(topic) { 18 | assert.isFunction(topic); 19 | } 20 | } 21 | }, 22 | 'should go to next by default': { 23 | topic: function() { 24 | var fn = mod_status(), 25 | next = false; 26 | 27 | fn({ 28 | url: '/foo' 29 | }, {}, function() { 30 | next = true; 31 | }); 32 | 33 | return next; 34 | }, 35 | 'should be true': function(topic) { 36 | assert.isTrue(topic); 37 | } 38 | }, 39 | 'should send good response': { 40 | topic: function() { 41 | var fn = mod_status(), 42 | code = null, 43 | next = false, 44 | text = null, 45 | req = { 46 | url: '/status.html' 47 | }; 48 | 49 | fn(req, { 50 | writeHead: function(c) { 51 | code = c; 52 | }, 53 | end: function(d) { 54 | text = d; 55 | } 56 | }, function() { 57 | next = true; 58 | }); 59 | 60 | return { 61 | code: code, 62 | text: text, 63 | next: next, 64 | parsedUrl : req.parsedUrl 65 | }; 66 | }, 67 | 'next should be false': function(topic) { 68 | assert.isFalse(topic.next); 69 | }, 70 | 'data should be OK': function(topic) { 71 | assert.equal(topic.text, 'OK'); 72 | }, 73 | 'code should be 200': function(topic) { 74 | assert.equal(topic.code, 200); 75 | }, 76 | 'request should be stamped with parse_url': function(topic) { 77 | assert.isObject(topic.parsedUrl); 78 | } 79 | }, 80 | 'should send bad response': { 81 | topic: function() { 82 | var fn = mod_status({ 83 | check: function() { return false; } 84 | }), 85 | code = null, 86 | next = false, 87 | text = null; 88 | 89 | fn({ 90 | url: '/status.html' 91 | }, { 92 | writeHead: function(c) { 93 | code = c; 94 | }, 95 | end: function(d) { 96 | text = d; 97 | } 98 | }, function() { 99 | next = true; 100 | }); 101 | 102 | return { 103 | code: code, 104 | text: text, 105 | next: next 106 | }; 107 | }, 108 | 'next should be false': function(topic) { 109 | assert.isFalse(topic.next); 110 | }, 111 | 'data should be Not Found': function(topic) { 112 | assert.equal(topic.text, 'Not Found'); 113 | }, 114 | 'code should be 404': function(topic) { 115 | assert.equal(topic.code, 404); 116 | } 117 | }, 118 | 'should send good response with node version': { 119 | topic: function() { 120 | var fn = mod_status({ 121 | version: true 122 | }), 123 | code = null, 124 | next = false, 125 | text = null; 126 | 127 | fn({ 128 | url: '/status.html' 129 | }, { 130 | writeHead: function(c) { 131 | code = c; 132 | }, 133 | end: function(d) { 134 | text = d; 135 | } 136 | }, function() { 137 | next = true; 138 | }); 139 | 140 | return { 141 | code: code, 142 | text: text, 143 | next: next 144 | }; 145 | }, 146 | 'next should be false': function(topic) { 147 | assert.isFalse(topic.next); 148 | }, 149 | 'data should be OK - Node: VERSION': function(topic) { 150 | assert.equal(topic.text, 'OK - Node: ' + process.version); 151 | }, 152 | 'code should be 200': function(topic) { 153 | assert.equal(topic.code, 200); 154 | } 155 | }, 156 | 'should send good response with uptime': { 157 | topic: function() { 158 | var fn = mod_status({ 159 | uptime: true 160 | }), 161 | code = null, 162 | next = false, 163 | text = null; 164 | 165 | fn({ 166 | url: '/status.html' 167 | }, { 168 | writeHead: function(c) { 169 | code = c; 170 | }, 171 | end: function(d) { 172 | text = d; 173 | } 174 | }, function() { 175 | next = true; 176 | }); 177 | 178 | return { 179 | code: code, 180 | text: text, 181 | next: next 182 | }; 183 | }, 184 | 'next should be false': function(topic) { 185 | assert.isFalse(topic.next); 186 | }, 187 | 'data should contain Uptime info': function(topic) { 188 | assert.ok(/- Uptime: /.test(topic.text)); 189 | }, 190 | 'code should be 200': function(topic) { 191 | assert.equal(topic.code, 200); 192 | } 193 | }, 194 | 'should send good response with custom text': { 195 | topic: function() { 196 | var fn = mod_status({ 197 | text: 'THIS STUFFS WORKS', 198 | uptime: true 199 | }), 200 | code = null, 201 | next = false, 202 | text = null; 203 | 204 | fn({ 205 | url: '/status.html' 206 | }, { 207 | writeHead: function(c) { 208 | code = c; 209 | }, 210 | end: function(d) { 211 | text = d; 212 | } 213 | }, function() { 214 | next = true; 215 | }); 216 | 217 | return { 218 | code: code, 219 | text: text, 220 | next: next 221 | }; 222 | }, 223 | 'next should be false': function(topic) { 224 | assert.isFalse(topic.next); 225 | }, 226 | 'data should not contain Uptime info': function(topic) { 227 | assert.isFalse(/- Uptime: /.test(topic.text)); 228 | }, 229 | 'data should contain custom text': function(topic) { 230 | assert.equal(topic.text, 'THIS STUFFS WORKS'); 231 | }, 232 | 'code should be 200': function(topic) { 233 | assert.equal(topic.code, 200); 234 | } 235 | }, 236 | 'should use parsedUrl if its already there': { 237 | topic: function() { 238 | var fn = mod_status(), 239 | code = null, 240 | next = false, 241 | text = null, 242 | req = { 243 | url: '/foo', 244 | parsedUrl : { 245 | pathname : '/status.html' 246 | } 247 | }; 248 | 249 | fn(req, { 250 | writeHead: function(c) { 251 | code = c; 252 | }, 253 | end: function(d) { 254 | text = d; 255 | } 256 | }, function() { 257 | next = true; 258 | }); 259 | 260 | return { 261 | code: code, 262 | text: text, 263 | next: next 264 | }; 265 | }, 266 | 'next should be false': function(topic) { 267 | assert.isFalse(topic.next); 268 | }, 269 | 'data should be OK': function(topic) { 270 | assert.equal(topic.text, 'OK'); 271 | }, 272 | 'code should be 200': function(topic) { 273 | assert.equal(topic.code, 200); 274 | } 275 | } 276 | 277 | }; 278 | 279 | 280 | vows.describe('mod_status').addBatch(tests)['export'](module); 281 | --------------------------------------------------------------------------------