-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
40 lines (35 loc) · 1.15 KB
/
main.js
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
const express = require('express');
const bodyParser = require("body-parser");
const figlet = require('figlet');
const app = express();
const blockchain = require('./src/main/nodejs/blockchain/bigchainDb');
const bigchainDB = new blockchain.BigchainDbConnection();
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
// respond with "hello world" when a GET request is made to the homepage
app.get('/weather/lon/:lon/lat/:lat', function (req, res) {
let params = req.params;
return bigchainDB.retrieveWeatherData(params.lon, params.lat)
.then((data) => {
res.send(data)
})
.catch((err) => {
res.status(500).send({ error: err });
})
});
app.post('/weather', function (req, res) {
return bigchainDB.storeWeatherData(req.body)
.then((result) => {
res.send(result)
})
.catch((err) => {
res.status(500).send({ error: err });
})
});
console.log(figlet.textSync(' THOR', {
font: 'Standard',
horizontalLayout: 'default',
verticalLayout: 'default'
}));
console.log("⚡ Decentralised Weather Data ⚡");
app.listen(3000);