-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
50 lines (38 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
// express to run server and routes
const express = require('express')
// start-up instance of app
const app = express();
/* include dependencies */
//bodyParser as middleware
const bodyParser = require('body-parser')
app.use(bodyParser.urlencoded({ extended: false}));
app.use(bodyParser.json());
//cors
const cors = require('cors')
app.use(cors());
const path = require('path');
/* Initializing the main project folder */
app.use(express.static(path.join('website')));
// Spin up the server
const port = 3000;
const server = app.listen(port, listening);
function listening() {
console.log("server running");
console.log(`running on localhost: ${port}`);
}
// app endpoint
let projectData = {};
/* get route */
app.get('/get', sendData);
function sendData(req, res) {
res.send(projectData);
}
/* post route */
app.post('/addData', addData);
function addData(req,res){
projectData['userName'] = req.body.userName;
projectData['date'] = req.body.date;
projectData['temperature'] = req.body.temperature;
projectData['userFeel'] = req.body.userFeel;
res.send(projectData);
}