forked from alboz1/Weather-App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
22 lines (17 loc) · 779 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const http = require('http');
require('dotenv').config();
const getWeatherInfo = require('./controllers/getWeatherInfo');
const staticFiles = require('./controllers/staticFiles');
const API_KEY = process.env.API_KEY;
const port = process.env.PORT || 4000;
const app = http.createServer((req, res) => {
if (req.url.includes('/current-weather')) {
getWeatherInfo(req, res, API_KEY, 'https://api.openweathermap.org/data/2.5/weather?');
} else if (req.url.includes('/forecast-weather')) {
getWeatherInfo(req, res, API_KEY, 'https://api.openweathermap.org/data/2.5/forecast/daily?cnt=6&');
} else {
//serve any file in the public folder
staticFiles(req, res);
}
});
app.listen(port, () => console.log(`Listening to port ${port}`));