diff --git a/lib/application.js b/lib/application.js index 601728a..013724d 100644 --- a/lib/application.js +++ b/lib/application.js @@ -13,6 +13,7 @@ var Cookies = require('cookies'); var accepts = require('accepts'); var assert = require('assert'); var http = require('http'); +var only = require('only'); var co = require('co'); /** @@ -68,6 +69,22 @@ app.listen = function(){ 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`. * @@ -197,4 +214,4 @@ function *respond(next){ this.length = Buffer.byteLength(body); if (head) return res.end(); res.end(body); -} +} \ No newline at end of file diff --git a/package.json b/package.json index bea995e..72c192c 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,8 @@ "fresh": "~0.2.1", "koa-compose": "~2.2.0", "cookies": "~0.4.0", - "delegates": "0.0.3" + "delegates": "0.0.3", + "only": "0.0.2" }, "devDependencies": { "should": "~3.1.0", diff --git a/test/application.js b/test/application.js index 478b348..f2c56df 100644 --- a/test/application.js +++ b/test/application.js @@ -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(){ it('should compose middleware', function(done){ var app = koa();