remove app.jsonSpaces setting. Closes #202

This commit is contained in:
TJ Holowaychuk 2014-01-31 18:39:47 -08:00
parent ea5757ff57
commit aa08845c70
4 changed files with 4 additions and 34 deletions

View file

@ -79,7 +79,6 @@ app.listen(3000);
- `app.env` defaulting to the __NODE_ENV__ or "development" - `app.env` defaulting to the __NODE_ENV__ or "development"
- `app.proxy` when true proxy header fields will be trusted - `app.proxy` when true proxy header fields will be trusted
- `app.subdomainOffset` offset of `.subdomains` to ignore [2] - `app.subdomainOffset` offset of `.subdomains` to ignore [2]
- `app.jsonSpaces` default JSON response spaces [2]
- `app.outputErrors` output err.stack to stderr [false in "test" environment] - `app.outputErrors` output err.stack to stderr [false in "test" environment]
## app.listen(...) ## app.listen(...)

View file

@ -130,15 +130,6 @@ so you can make a correction.
The Content-Type is defaulted to application/json. The Content-Type is defaulted to application/json.
#### Notes
To alter the JSON response formatting use the `app.jsonSpaces`
setting, for example to compress JSON responses set:
```js
app.jsonSpaces = 0;
```
### res.get(field) ### res.get(field)
Get a response header field value with case-insensitive `field`. Get a response header field value with case-insensitive `field`.

View file

@ -40,7 +40,6 @@ function Application() {
this.outputErrors = 'test' != this.env; this.outputErrors = 'test' != this.env;
this.subdomainOffset = 2; this.subdomainOffset = 2;
this.poweredBy = true; this.poweredBy = true;
this.jsonSpaces = 2;
this.middleware = []; this.middleware = [];
this.context = Object.create(context); this.context = Object.create(context);
this.request = Object.create(request); this.request = Object.create(request);
@ -194,7 +193,7 @@ function *respond(next){
} }
// body: json // body: json
body = JSON.stringify(body, null, this.app.jsonSpaces); body = JSON.stringify(body);
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

@ -406,31 +406,12 @@ describe('app.respond', function(){
var server = app.listen(); var server = app.listen();
request(server)
.get('/')
.expect('Content-Type', 'application/json')
.expect('{\n "hello": "world"\n}', done);
})
describe('when app.jsonSpaces is altered', function(){
it('should reflect in the formatting', function(done){
var app = koa();
app.jsonSpaces = 0;
app.use(function *(){
this.body = { hello: 'world' };
});
var server = app.listen();
request(server) request(server)
.get('/') .get('/')
.expect('Content-Type', 'application/json') .expect('Content-Type', 'application/json')
.expect('{"hello":"world"}', done); .expect('{"hello":"world"}', done);
}) })
}) })
})
describe('when an error occurs', function(){ describe('when an error occurs', function(){
it('should emit "error" on the app', function(done){ it('should emit "error" on the app', function(done){