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({ price: 33 }); }); app.get("/users/:userId/assets", (req, res) => { 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) => { //TODO implement... res.send({ assetId: req.params.assetId, balance: 150 }); }); app.post("/buy", (req, res) => { //TODO implement... res.status(201); }); app.listen(port, () => { console.log(`Listening at http://localhost:${port}`) })