Skip to content

Commit

Permalink
Agregamos los valores por defecto al módulo.
Browse files Browse the repository at this point in the history
Cubrimos 100%

Con @estefi-capece
  • Loading branch information
emilioplatzer committed May 11, 2015
1 parent 90154e5 commit 63e0f21
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ a way to kill node process from client navigator. Something like http://yoursite

[![version](https://img.shields.io/npm/v/kill-9.svg)](https://npmjs.org/package/kill-9)
[![downloads](https://img.shields.io/npm/dm/kill-9.svg)](https://npmjs.org/package/kill-9)
[![linux](https://img.shields.io/travis/codenautas/kill-9/master.svg)](https://travis-ci.org/codenautas/kill-9)
[![build](https://img.shields.io/travis/codenautas/kill-9/master.svg)](https://travis-ci.org/codenautas/kill-9)
[![coverage](https://img.shields.io/coveralls/codenautas/kill-9/master.svg)](https://coveralls.io/r/codenautas/kill-9)
[![dependencies](https://img.shields.io/david/codenautas/kill-9.svg)](https://david-dm.org/codenautas/kill-9)

Expand Down
34 changes: 22 additions & 12 deletions index.js → kill-9.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* GNU Licensed
*/

"use strict";

/**
* Module dependencies.
*/
Expand All @@ -16,43 +18,51 @@ var express = require('express');
* @api public
*/

exports = module.exports = function kill9(opts){
var kill9 = exports = module.exports = function kill9(opts){
var killer=express();
var _process=opts.process || process;
var pid=opts.pid || _process.pid;
if(opts.statusKilled>=300 && opts.statusKilled<=303 && !('location' in opts)){
if(kill9.isRedirectCode(opts.statusKilled) && !('location' in opts)){
throw new Error('kill-9: options.location required');
};
if(opts.statusBad>=300 && opts.statusBad<=303 && !('locationBad' in opts)){
if(kill9.isRedirectCode(opts.statusBad) && !('locationBad' in opts)){
throw new Error('kill-9: options.locationBad required');
};
if(!(opts.statusKilled>=300 && opts.statusKilled<=303) && ('location' in opts)){
if(!kill9.isRedirectCode(opts.statusKilled) && ('location' in opts)){
throw new Error('kill-9: options.location is only for redirect');
};
if(!(opts.statusBad>=300 && opts.statusBad<=303) && ('locationBad' in opts)){
if(!kill9.isRedirectCode(opts.statusBad) && ('locationBad' in opts)){
throw new Error('kill-9: options.locationBad is only for redirect');
};
if(opts.log){
console.log('kill-9 installed. '+opts.log);
if(!opts.pid){
console.log('pid='+pid);
}
console.log('pid='+pid);
}
killer.get('/'+(opts.statement||'kill-9'),function killer(req,res){
if(req.query.pid==pid){
res.status(opts.statusKilled||200);
res.status(opts.statusKilled||kill9.defaults.statusKilled);
if(opts.location){
res.header('Location',opts.location);
}
res.send(opts.messageKilled||'kill -9 success');
_process.exit(opts.exitCode||0);
_process.exit(opts.exitCode||kill9.defaults.exitCode);
}else{
res.status(opts.statusBad||404);
res.status(opts.statusBad||kill9.defaults.statusBad);
if(opts.locationBad){
res.header('Location',opts.locationBad);
}
res.send(opts.messageBad||'kill -9 unknown');
}
});
return killer;
}
};

kill9.defaults={
statusKilled:200,
exitCode:0,
statusBad:404
};

kill9.isRedirectCode = function isRedirectCode(htmlCode){
return htmlCode>=300 && htmlCode<=303;
};
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"name": "kill-9",
"description": "A way for kill node server from client navigator",
"version": "0.2.1",
"version": "0.2.2",
"author": "Emilio Platzer <emilioplatzer@outlook.com>",
"license": "GPL-2.0",
"repository": "codenautas/kill-9",
"main": "kill-9.js",
"dependencies": {
"express": ""
"express": ">=4.12.3"
},
"devDependencies": {
"istanbul": "0.3.5",
"mocha": "~2.1.0",
"istanbul": "0.3.13",
"mocha": "~2.2.4",
"supertest": "~0.15.0"
},
"files": [
Expand Down
4 changes: 2 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ describe('kill9()', function(){
var createRedirectServer;
before(function () {
createRedirectServer = function(reference){
kill9.defaults.exitCode=999;
return createServer({
exitCode:16,
process:{pid:555, exit:function(code){ reference.code = code; }},
statusKilled:300,
location:"other_site.kom/?killed=1",
Expand All @@ -100,7 +100,7 @@ describe('kill9()', function(){
.expect(300)
.end(function(err, res){
if (err) return done(err);
assert.equal(reference.code,16);
assert.equal(reference.code,999);
done();
});
});
Expand Down

0 comments on commit 63e0f21

Please sign in to comment.