Comparing version 0.1.3 to 0.1.4
@@ -12,29 +12,17 @@ "use strict"; | ||
const axios_1 = require("axios"); | ||
const Boom = require("boom"); | ||
const _ = require("lodash"); | ||
function makeRequest(topic, payload, target) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
const response = yield axios_1.default.post(target, { | ||
topic, | ||
payload | ||
}); | ||
return response.data.payload; | ||
} | ||
catch (err) { | ||
if (err.response && err.response.data) { | ||
const errData = err.response.data; | ||
const boomError = _.get(errData, 'output.payload'); | ||
if (boomError) { | ||
throw boomError; | ||
} | ||
else { | ||
throw new Error(errData.message); | ||
} | ||
return axios_1.default.post(target, { topic, payload }) | ||
.then(response => response.data.payload) | ||
.catch(err => { | ||
const errData = _.get(err, 'response.data'); | ||
if (errData) { | ||
throw Boom.create(_.get(errData, 'output.statusCode'), _.get(errData, 'output.payload.message')); | ||
} | ||
else { | ||
throw err; | ||
} | ||
} | ||
throw err; | ||
}); | ||
}); | ||
} | ||
exports.default = makeRequest; |
@@ -21,2 +21,3 @@ /// <reference types="node" /> | ||
private app; | ||
private router; | ||
private redis; | ||
@@ -23,0 +24,0 @@ private port; |
@@ -12,7 +12,8 @@ "use strict"; | ||
const Bluebird = require("bluebird"); | ||
const bodyParser = require("body-parser"); | ||
const Boom = require("boom"); | ||
const express = require("express"); | ||
const Redis = require("ioredis"); | ||
const Joi = require("joi"); | ||
const Koa = require("koa"); | ||
const bodyParser = require("koa-bodyparser"); | ||
const Router = require("koa-router"); | ||
const hash = require("object-hash"); | ||
@@ -23,15 +24,19 @@ const makeRequest_1 = require("./makeRequest"); | ||
constructor(configs = {}) { | ||
this.app = express(); | ||
this.app.use(bodyParser.json()); | ||
this.app.post('/rpc', (req, res) => __awaiter(this, void 0, void 0, function* () { | ||
this.app = new Koa(); | ||
this.app.use(bodyParser({ | ||
enableTypes: ['json'] | ||
})); | ||
this.router = new Router(); | ||
this.router.post('/rpc', (ctx) => __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
const result = yield this.executeEndpoint(req.body.topic, req.body.payload); | ||
res.json({ payload: result }); | ||
const result = yield this.executeEndpoint(ctx.request.body.topic, ctx.request.body.payload); | ||
ctx.body = { payload: result }; | ||
} | ||
catch (err) { | ||
const boomError = Boom.boomify(err, { override: false }); | ||
res.status(boomError.output.statusCode); | ||
res.send(boomError); | ||
ctx.status = boomError.output.statusCode; | ||
ctx.body = boomError; | ||
} | ||
})); | ||
this.app.use(this.router.routes()); | ||
if (configs.redisUrl) { | ||
@@ -38,0 +43,0 @@ this.redis = new Redis(configs.redisUrl); |
{ | ||
"name": "chayen", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "An RPC framework with so much hype going on. such wow.", | ||
@@ -40,5 +40,7 @@ "main": "dist/index.js", | ||
"boom": "^6.0.0", | ||
"express": "^4.16.1", | ||
"ioredis": "^3.1.4", | ||
"joi": "^11.1.1", | ||
"koa": "^2.3.0", | ||
"koa-bodyparser": "^4.2.0", | ||
"koa-router": "^7.2.1", | ||
"lodash": "^4.17.4", | ||
@@ -50,6 +52,8 @@ "object-hash": "^1.1.8" | ||
"@types/boom": "^4.3.7", | ||
"@types/express": "^4.0.37", | ||
"@types/ioredis": "^0.0.25", | ||
"@types/jest": "^21.1.1", | ||
"@types/joi": "^10.4.3", | ||
"@types/koa": "^2.0.39", | ||
"@types/koa-bodyparser": "^3.0.25", | ||
"@types/koa-router": "^7.0.23", | ||
"@types/lodash": "^4.14.76", | ||
@@ -56,0 +60,0 @@ "@types/object-hash": "^0.5.29", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
129884
11
15
217
1
+ Addedkoa@^2.3.0
+ Addedkoa-bodyparser@^4.2.0
+ Addedkoa-router@^7.2.1
+ Added@hapi/bourne@3.0.0(transitive)
+ Addedany-promise@1.3.0(transitive)
+ Addedcache-content-type@1.0.1(transitive)
+ Addedco@4.6.0(transitive)
+ Addedco-body@6.2.0(transitive)
+ Addedcookies@0.9.1(transitive)
+ Addedcopy-to@2.0.1(transitive)
+ Addeddebug@3.2.74.3.7(transitive)
+ Addeddeep-equal@1.0.1(transitive)
+ Addeddelegates@1.0.0(transitive)
+ Addeddepd@1.1.2(transitive)
+ Addedhas-tostringtag@1.0.2(transitive)
+ Addedhttp-assert@1.5.0(transitive)
+ Addedhttp-errors@1.8.1(transitive)
+ Addedinflation@2.1.0(transitive)
+ Addedis-generator-function@1.0.10(transitive)
+ Addedisarray@0.0.1(transitive)
+ Addedkeygrip@1.1.0(transitive)
+ Addedkoa@2.15.3(transitive)
+ Addedkoa-bodyparser@4.4.1(transitive)
+ Addedkoa-compose@3.2.14.2.0(transitive)
+ Addedkoa-convert@2.0.0(transitive)
+ Addedkoa-router@7.4.0(transitive)
+ Addedonly@0.0.2(transitive)
+ Addedpath-to-regexp@1.9.0(transitive)
+ Addedstatuses@1.5.0(transitive)
+ Addedtsscmp@1.0.6(transitive)
+ Addedurijs@1.19.11(transitive)
+ Addedylru@1.4.0(transitive)
- Removedexpress@^4.16.1
- Removedarray-flatten@1.1.1(transitive)
- Removedcookie@0.7.1(transitive)
- Removedcookie-signature@1.0.6(transitive)
- Removedencodeurl@2.0.0(transitive)
- Removedetag@1.8.1(transitive)
- Removedexpress@4.21.1(transitive)
- Removedfinalhandler@1.3.1(transitive)
- Removedforwarded@0.2.0(transitive)
- Removedipaddr.js@1.9.1(transitive)
- Removedmerge-descriptors@1.0.3(transitive)
- Removedmime@1.6.0(transitive)
- Removedpath-to-regexp@0.1.10(transitive)
- Removedproxy-addr@2.0.7(transitive)
- Removedrange-parser@1.2.1(transitive)
- Removedsend@0.19.0(transitive)
- Removedserve-static@1.16.2(transitive)
- Removedutils-merge@1.0.1(transitive)