-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
34 lines (28 loc) · 865 Bytes
/
app.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
const express = require('express');
const cors = require('cors');
const app = express();
const port = 3000;
require("dotenv").config();
app.use(cors({
origin: 'http://127.0.0.1:3000',
optionsSuccessStatus : 200
}))
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use("/static", express.static('./static/'));
app.get('/', (req, res) => {
console.log("GET req received");
res.sendFile(__dirname + '/static/home.html');
console.log("GET req finished");
})
app.post('/submit', (req, res) => {
console.log("POST req received");
fetch(`http://api.weatherstack.com/current?access_key=${process.env.API_KEY}&query=${req.body.location}`)
.then(resObj => resObj.text())
.then(data => {
res.json(data);
})
})
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})