Commit f81c228f authored by Evgeniy Zaitsev's avatar Evgeniy Zaitsev
Browse files

v0.0.12

parent 318e2dea
......@@ -5,7 +5,6 @@ const http = require('http');
const https = require('https');
const koa = require('koa');
const validate = require('koa-validate');
const sslify = require('koa-sslify');
const Promise = require('bluebird');
const mysql = require('mysql');
const fetch = require('node-fetch');
......@@ -18,6 +17,7 @@ const lvisEndpoints = require('./lib/lvisEndpoints');
const createTables = require('./lib/createTables');
const logger = require('./lib/logger');
const bodyParser = require('./middlewares/bodyParser');
const errors = require('./middlewares/errors');
const router = require('./router');
......@@ -28,12 +28,12 @@ class SDK {
validate(this.server);
this.server.use(bodyParser);
this.server.use(errors);
this.server.use(require('koa-bodyparser')());
this.server.use(router.routes());
if (this.config.httpsPort) {
this.server.use(sslify());
this.server.use(require('koa-sslify')());
}
this.server.env = this.config.env || 'production';
......
const parse = require('co-body');
function * bodyParser(next) {
this.request.bodyRow = yield parse.text(this.request);
try {
this.request.body = JSON.parse(this.request.bodyRow);
} catch (e) {
this.request.body = this.request.bodyRow;
}
yield next;
}
module.exports = bodyParser;
const sha1 = require('sha1');
const parse = require('co-body');
function * checkToken(next) {
const salt = this.checkHeader('x-lvis-salt').notBlank().value;
const signature = this.checkHeader('x-lvis-signature').notBlank().value;
const querystring = this.request.querystring ? '?' + this.request.querystring : '';
this.logger.log(__filename, 'path:', this.request.path);
this.logger.log(__filename, 'headers:', JSON.stringify({salt, signature}));
this.logger.log(__filename, 'body:', JSON.stringify(this.request.body));
this.logger.log(__filename, 'querystring:', querystring);
this.logger.log(__filename, 'body row:', this.request.bodyRow);
this.throwResponseErrorIfNeed(this.errors);
const reqBody = yield parse.text(this.request);
const querystring = this.request.querystring ? '?' + this.request.querystring : '';
this.logger.log(__filename, '\n', this.request.path, '\n', this.request.querystring, '\n', reqBody);
const signeableContent = this.request.path + querystring + reqBody;
const signeableContent = this.request.path + querystring + this.request.bodyRow;
const str = this.config.accessToken + signeableContent + salt;
this.logger.log(__filename, 'sa1 from str:', str);
......
{
"name": "service-sdk",
"version": "0.0.11",
"version": "0.0.12",
"private": true,
"description": "Service SDK for LViS",
"keywords": [],
......@@ -15,7 +15,6 @@
"co-body": "^4.2.0",
"debug": "^2.2.0",
"koa": "^1.2.4",
"koa-bodyparser": "^2.2.0",
"koa-json": "^1.1.3",
"koa-router": "^5.4.0",
"koa-sslify": "^1.1.0",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment