|
|
@@ -1,9 +1,16 @@
|
|
|
const express = require("express");
|
|
|
const res = require("express/lib/response");
|
|
|
+const http = require("http");
|
|
|
|
|
|
const app = express();
|
|
|
const port = 3000;
|
|
|
|
|
|
+//TODO load these values from setting or env
|
|
|
+
|
|
|
+const irohaApiHost = "localhost";
|
|
|
+const irohaApiPort = 5000;
|
|
|
+const irohaDomain = "test";
|
|
|
+
|
|
|
app.post("/price", (req, res) => {
|
|
|
//TODO implement price calculation depending on extent area
|
|
|
res.send({
|
|
|
@@ -12,13 +19,33 @@ app.post("/price", (req, res) => {
|
|
|
});
|
|
|
|
|
|
app.get("/users/:userId/assets", (req, res) => {
|
|
|
- //TODO implement...
|
|
|
- res.send({
|
|
|
- assets: [
|
|
|
- {assetId: "test", balance: 20},
|
|
|
- {assetId: "doge", balance: 150}
|
|
|
- ]
|
|
|
- })
|
|
|
+
|
|
|
+ let output = '';
|
|
|
+
|
|
|
+ let options = {
|
|
|
+ hostname: irohaApiHost,
|
|
|
+ port: irohaApiPort,
|
|
|
+ path: '/accounts/' + req.params.userId + '@' + irohaDomain + '/assets/',
|
|
|
+ method: 'GET',
|
|
|
+ }
|
|
|
+
|
|
|
+ let irohaReq = http.request(options, irohaRes => {
|
|
|
+
|
|
|
+ irohaRes.on("data", chunk => {
|
|
|
+ output += chunk;
|
|
|
+ });
|
|
|
+
|
|
|
+ irohaRes.on('end', () => {
|
|
|
+ res.send(JSON.parse(output));
|
|
|
+ })
|
|
|
+ });
|
|
|
+
|
|
|
+ irohaReq.on("error", error => {
|
|
|
+ console.error(error);
|
|
|
+ res.send(error);
|
|
|
+ });
|
|
|
+
|
|
|
+ irohaReq.end();
|
|
|
});
|
|
|
|
|
|
app.get("/users/:userId/assets/:assetId", (req, res) => {
|