+ hudozka-middlewares, + hudozka-api-v1
This commit is contained in:
1 parent
6347e4db35
commit
35cc7c0caa
17 files changed
+175
-61
No files matched your search
@@ -0,0 +1,3 @@
|
||||
node_modules/
|
||||
lib/
|
||||
.idea/
|
||||
@@ -0,0 +1,2 @@
|
||||
src/
|
||||
.idea/
|
||||
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "hudozka-middlewares",
|
||||
"private": true,
|
||||
"version": "0.0.1",
|
||||
"description": "",
|
||||
"main": "lib/index.js",
|
||||
"scripts": {
|
||||
"compile": "babel --presets es2015,stage-0 src/ -d lib/",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"ejson": "^2.1.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-cli": "^6.6.5",
|
||||
"babel-preset-es2015": "^6.6.0",
|
||||
"babel-preset-stage-0": "^6.5.0"
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export {ejson} from './ejson';
|
||||
export {ensureServiceAuth} from './ensureServiceAuth';
|
||||
Reference in new issue
Block a user