Skip to content

Commit 9558453

Browse files
committed
Add @koa/json-filter, allowing user to limit the fields being returned
This doesn't reduce the query, and should play nicely with cache. All it does is remove any fields that aren't explicitly asked for, using the `filter` query.
1 parent c2c8b6c commit 9558453

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
},
3333
"homepage": "https://github.com/r-spacex/SpaceX-API",
3434
"dependencies": {
35+
"@koa/json-filter": "^1.0.0",
3536
"cheerio": "^1.0.0-rc.2",
3637
"fuzzball": "^1.1.5",
3738
"koa": "^2.5.3",

src/app.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const cache = require('koa-redis-cache');
44
const compress = require('koa-compress');
55
const cors = require('koa2-cors');
66
const helmet = require('koa-helmet');
7+
const jsonFilter = require('@koa/json-filter');
78
const Koa = require('koa');
89
const logger = require('koa-morgan');
910
const MongoClient = require('mongodb');
@@ -95,6 +96,9 @@ if (process.env.NODE_ENV === 'production') {
9596
app.use(cache(options));
9697
}
9798

99+
// Allow user to restrict the keys returned
100+
app.use(jsonFilter());
101+
98102
// Allow pretty print via pretty=true querystring
99103
// Pretty printed json will NOT be cached
100104
app.use(json({ pretty: false, param: { pretty: true } }));

0 commit comments

Comments
 (0)