-
Notifications
You must be signed in to change notification settings - Fork 19
/
server.js
58 lines (58 loc) · 1.79 KB
/
server.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#~~
const postmanRequest = require('postman-request');
const geoCode = require('./utils/geocode');
const foreCast = require('./utils/forecaste');
const server = require('express')();
const path = require('path');
const bodyParser = require('body-parser');
server.set('view engine', 'hbs');
server.use(bodyParser.urlencoded({ extended: true }));
server.get('', (req, res) => {
res.render('index');
})
server.post('/', (req, res) => {
if(!req.body.search_address)
return res.redirect('/');
geoCode(req.body.search_address, (error, data) => {
if(error)
{
res.send(error);
}
else
{
foreCast(data.latitude, data.longitude, (error, data) => {
if(error)
{
res.send(error);
}
else
{
res.render('weather', {
temperature: data.temperature,
precipitation: data.precipitation,
weather_icons: data.weather_icons[0],
weather_descriptions: data.weather_descriptions[0],
wind_speed: data.wind_speed,
wind_dir: data.wind_dir,
pressure: data.pressure,
humidity: data.humidity,
name: data.name,
country: data.country,
region: data.region,
lat: data.lat,
lon: data.lon
});
}
});
}
});
});
server.get('*', (req, res) => {
res.send("404");
})
server.listen(process.env.PORT || 5000, () => {
console.log("Server is running on port 5000"); #port 5000 open
});
#~
#EOF
#~