+ ejson middleware
This commit is contained in:
1 parent
aa18f77ea7
commit
82b9a6b56b
3 files changed
+21
-1
No files matched your search
@@ -21,6 +21,7 @@
|
|||||||
"babel-preset-es2015": "^6.5.0",
|
"babel-preset-es2015": "^6.5.0",
|
||||||
"babel-preset-stage-0": "^6.5.0",
|
"babel-preset-stage-0": "^6.5.0",
|
||||||
"co": "^4.4.0",
|
"co": "^4.4.0",
|
||||||
|
"ejson": "^2.1.2",
|
||||||
"instagram-node": "^0.5.1",
|
"instagram-node": "^0.5.1",
|
||||||
"koa": "^2.0.0-alpha.3",
|
"koa": "^2.0.0-alpha.3",
|
||||||
"koa-bodyparser": "^3.0.0",
|
"koa-bodyparser": "^3.0.0",
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import {parse} from 'ejson';
|
||||||
|
|
||||||
|
export function ejson() {
|
||||||
|
return async (ctx, next) => {
|
||||||
|
let type = ctx.request.headers['content-type'];
|
||||||
|
let data = ctx.request.body;
|
||||||
|
|
||||||
|
if (type === 'application/ejson'){
|
||||||
|
data = typeof data === 'string' ? data : JSON.stringify(data);
|
||||||
|
ctx.request.body = parse(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
await next();
|
||||||
|
};
|
||||||
|
}
|
||||||
+5
-1
@@ -25,7 +25,11 @@ export default function(){
|
|||||||
const app = new Koa();
|
const app = new Koa();
|
||||||
app.proxy = true;
|
app.proxy = true;
|
||||||
|
|
||||||
app.use(bodyParser());
|
app.use(bodyParser({
|
||||||
|
extendTypes: {
|
||||||
|
json: 'application/ejson'
|
||||||
|
}
|
||||||
|
}));
|
||||||
app.use($(logger()));
|
app.use($(logger()));
|
||||||
app.use(api());
|
app.use(api());
|
||||||
app.use($(conditional()));
|
app.use($(conditional()));
|
||||||
|
|||||||
Reference in new issue
Block a user