-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
46 lines (30 loc) · 930 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
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Empty JS object to act as endpoint for all routes
projectData = {};
// Require Express to run server and routes
const port = 8000
const express = require("express")
const cors = require("cors")
const bodyParser = require("body-parser")
// Start-up an instance of the app
const app = express()
/* Middleware */
// Express config for body-parser usage in middleware
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
// Cors for cross origin allowance
app.use(cors())
// Initialise the main project folder
app.use(express.static('website'));
// Setup Server
app.listen(port, () => {
console.log(`Server initiated on port: ${port}`)
})
app.get("/storedData", (req, res) => {
res.send(projectData)
})
app.post("/currentData", (req, res) => {
projectData.temp = req.body.temp
projectData.date = req.body.date
projectData.feelings = req.body.feelings
res.end()
})