add app.toJSON()

This commit is contained in:
TJ Holowaychuk 2014-03-11 11:01:33 -07:00
parent f0e353d6a0
commit 895cf4040c
3 changed files with 34 additions and 2 deletions

View File

@ -13,6 +13,7 @@ var Cookies = require('cookies');
var accepts = require('accepts'); var accepts = require('accepts');
var assert = require('assert'); var assert = require('assert');
var http = require('http'); var http = require('http');
var only = require('only');
var co = require('co'); var co = require('co');
/** /**
@ -68,6 +69,22 @@ app.listen = function(){
return server.listen.apply(server, arguments); return server.listen.apply(server, arguments);
}; };
/**
* Return JSON representation.
*
* @return {Object}
* @api public
*/
app.toJSON = function(){
return only(this, [
'outputErrors',
'subdomainOffset',
'poweredBy',
'env'
]);
};
/** /**
* Use the given middleware `fn`. * Use the given middleware `fn`.
* *
@ -197,4 +214,4 @@ function *respond(next){
this.length = Buffer.byteLength(body); this.length = Buffer.byteLength(body);
if (head) return res.end(); if (head) return res.end();
res.end(body); res.end(body);
} }

View File

@ -30,7 +30,8 @@
"fresh": "~0.2.1", "fresh": "~0.2.1",
"koa-compose": "~2.2.0", "koa-compose": "~2.2.0",
"cookies": "~0.4.0", "cookies": "~0.4.0",
"delegates": "0.0.3" "delegates": "0.0.3",
"only": "0.0.2"
}, },
"devDependencies": { "devDependencies": {
"should": "~3.1.0", "should": "~3.1.0",

View File

@ -47,6 +47,20 @@ describe('app', function(){
}) })
}) })
describe('app.toJSON()', function(){
it('should work', function(){
var app = koa();
var obj = app.toJSON();
obj.should.eql({
outputErrors: false,
subdomainOffset: 2,
poweredBy: true,
env: 'test'
});
})
})
describe('app.use(fn)', function(){ describe('app.use(fn)', function(){
it('should compose middleware', function(done){ it('should compose middleware', function(done){
var app = koa(); var app = koa();