-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
44 lines (34 loc) · 1.02 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
const bodyParser = require("body-parser");
const cors = require("cors");
const express = require("express");
// Setup empty JS object to act as endpoint for all routes
let projectData = {};
// Start up an instance of app
const app = express();
/* Dependencies */
/* Middleware*/
// Here we are configuring express to use body-parser as middle-ware.
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
// Cors for cross origin allowance
app.use(cors());
// Initialize the main project folder
app.use(express.static("website"));
// Spin up the server
const port = 3000;
app.listen(port, () => {
// Callback to debug
console.log(`Weather Journal app listening on port: ${port}`);
});
// Initialize all route with a callback function
// Get Route
app.get("/get-latest", (req, res) => {
res.send(JSON.stringify(projectData));
});
// Post Route
app.post("/save", (req, res) => {
projectData.temp = req.body.temp;
projectData.date = req.body.date;
projectData.content = req.body.content;
res.end();
});