-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
61 lines (39 loc) · 1.09 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
59
60
//Empty JS object to act as endpoint for all routes
projectData = {};
// Express to run server and routes
const express = require('express');
// Start up an instance of app
const app = express();
// middleware
const bodyParser = require('body-parser')
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
// Cors for cross origin allowance
const cors = require('cors');
app.use(cors());
//Initializing the main project folder
app.use(express.static('website'));
//setup server
const port = 8000;
const server = app.listen(port, listening);
function listening(){
console.log("server running");
console.log(`server is running on localhost: ${port}`);
}
//add GET route
app.get('/all', sendData);
function sendData(req, res) {
res.send(projectData);
};
//add POST route
app.post('/add', addData )
function addData (req, res){
console.log(req.body)
newEntry = {
temp: req.body.temp,
date: req.body.date,
content: req.body.content
}
projectData = newEntry;
//res.send(projectData);
};