+ hudozka-middlewares, + hudozka-api-v1

This commit is contained in:
tmshv committed 2016-03-26 21:53:20 +03:00
1 parent 6347e4db35
commit 35cc7c0caa
17 files changed
+175 -61

No files matched your search

+15
View File
@@ -0,0 +1,15 @@
import {parse} from 'ejson';
export function ejson(type='application/ejson') {
return async (ctx, next) => {
let t = ctx.request.headers['content-type'];
let data = ctx.request.body;
if (t === type){
data = typeof data === 'string' ? data : JSON.stringify(data);
ctx.request.body = parse(data);
}
await next();
};
}
@@ -0,0 +1,12 @@
export function ensureServiceAuth(auth) {
return async (ctx, next) => {
let service = ctx.request.headers['x-service-name'];
let token = ctx.request.headers['x-service-token'];
if (!auth(service, token)) {
ctx.status = 401;
} else {
await next();
}
};
}
+2
View File
@@ -0,0 +1,2 @@
export {ejson} from './ejson';
export {ensureServiceAuth} from './ensureServiceAuth';