+ 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
@@ -1,15 +0,0 @@
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();
};
}
-14
View File
@@ -1,14 +0,0 @@
import {checkAuth} from '../core/service';
export function ensureServiceAuth() {
return async (ctx, next) => {
let service = ctx.request.headers['x-service-name'];
let token = ctx.request.headers['x-service-token'];
if (!checkAuth(service, token)) {
ctx.status = 401;
} else {
await next();
}
};
}
-35
View File
@@ -1,35 +0,0 @@
let contains = (list, i) => list.indexOf(i) > -1;
export function queryValue(params) {
let keys = Object.keys(params);
return async (ctx, next) => {
let query = ctx.request.query;
ctx.request.query = Object.keys(query)
.reduce((q, i) => {
if(contains(keys, i)){
let fn = params[i];
q[i] = fn(q[i]);
}
return q;
}, query);
await next();
};
}
export function booleanify(){
return function(value){
if(value == 'true') return true;
if(value == '1') return true;
if(value == 'false') return false;
if(value == '0') return false;
return Boolean(value);
}
}
export function arrayify(sep){
return function(value){
return value.split(sep);
}
}