1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| const express = require('express'); const app = express(); const query = require("./query"); const invoke = require("./invoke"); var bodyParser = require('body-parser'); const port = 3000;
app.use(bodyParser.json()); app.use(bodyParser.urlencoded({extended: false}));
app.all('*',function (req, res, next) { res.header('Access-Control-Allow-Origin', '*'); res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With'); res.header('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS'); if (req.method === 'OPTIONS') { res.send(200); } else { next(); } });
app.get('/queryAllFishes', async (req, res) => res.send(await query("fishcc","queryAllFishes",new Array("x")))); app.get('/queryFish', async (req, res) => res.send( await query("fishcc", "queryFish", new Array(req.query.fish)) )); app.get('/queryHistory', async (req, res) => res.send( await query("fishcc", "queryHistory", new Array(req.query.fish)) ));
app.post("/updateHolder", async (req, res)=>{ res.send(await invoke(req.body.channel, req.body.chaincode, req.body.fcn, [req.body.fish, req.body.holder])) });
app.post("/recordFish", async (req, res)=>{ res.send( await invoke(req.body.channel, req.body.chaincode, req.body.fcn, [req.body.fish, req.body.holder, req.body.location, req.body.temperature, req.body.timestamp, req.body.vessel] )); });
app.listen(port, () => console.log(`Example app listening on port ${port}!`));
|