-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
39 lines (31 loc) · 909 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
const express = require('express');
const cors = require('cors');
const app = express();
/**
* Use the out-of-the-box express.json() and express.urlencoded() methods over the outdated option
* of adding body-parser middleware to handle POST requests
*/
app.use(express.urlencoded({ extended: false }));
app.use(express.json());
// Enable CORS for all requests
app.use(cors());
// Initialize project
app.use(express.static('client'));
// Server
const port = 3000;
const listening = () => {
// eslint-disable-next-line no-console
console.log('server started and listening on port', port);
};
app.listen(port, listening);
// Serves as "database" to hold project data
let projectData = {};
// GET route
app.get('/entries', (req, res) => {
res.send(projectData);
});
// POST route
app.post('/entry', (req, res) => {
projectData = req.body;
res.send({ success: true, message: 'Success' });
});