-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
43 lines (32 loc) · 1.03 KB
/
server.js
File metadata and controls
43 lines (32 loc) · 1.03 KB
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
// Setup empty JS object to act as endpoint for all routes
projectData = {};
// Require Express to run server and routes
const express = require('express');
// Start up an instance of app
const app=express();
const bodyParser = require('body-parser');
/* 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
const cors =require('cors');
app.use(cors());
// Initialize the main project folder
app.use(express.static('website'));
// Setup Server
const port = 8000;
const hostname = "127.0.0.1";
// function to test the server
const listening = () =>
console.log(`Server running at http://${hostname}:${port}/`);
// spin up the server
app.listen(port, listening);
const getAll = (req, res) => res.status(200).send(projectData);
app.get('/all',getAll);
const postData = (req, res) => {
projectData = req.body;
console.log(projectData);
res.status(200).send(projectData);
}
app.post("/add", postData);