import fetch from "node-fetch" import express from "express" const app = express(); const port = 3000; //TODO load these values from setting or env const irohaApiHost = "http://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", async (req, res) => { try{ res.send(await getUsersAssets(req.params.userId)); } catch(error){ console.error(error); res.status(500); res.send(error); } }); app.get("/users/:userId/assets/:assetId", async (req, res) => { try{ let response = await getUsersAssets(req.params.userId); let i = 0; for(i; i < response.assets.length; i++){ if(response.assets[i].assetId.startsWith(req.params.assetId)){ res.send(response.assets[i]); return; } } } catch(error){ console.error(error); res.status(500); res.send(error); } }); app.post("/buy", (req, res) => { //TODO implement... res.status(201); }); app.listen(port, () => { console.log(`Listening at http://localhost:${port}`) }); async function getUsersAssets(userId){ let response = await fetch(irohaApiHost + ':' + irohaApiPort + '/accounts/' + userId + '@' + irohaDomain + '/assets/'); return await response.json(); }