| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- 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}`)
- })
|