-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
49 lines (30 loc) · 1003 Bytes
/
Copy pathserver.js
File metadata and controls
49 lines (30 loc) · 1003 Bytes
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
const path = require('path');
const bodyParser = require('body-parser');
const cors = require('cors');
const express = require('express');
const app = express();
const PORT = 3000;
const booksController = require('./server/controllers')
app.use(cors());
app.use(bodyParser.json());
app.use(express.static(path.join(__dirname, './build')));
app.get('/books', (req, res) => {
res.status(200).json(res.locals.books)
})
app.post('/books', booksController.postBooks, (req, res) => {
res.status(200).send('OK')
})
// app.post('/books', booksController.deleteBooks, (req, res) => {
// res.status(200).send('OK')
// })
app.get('/', (req,res) => {
res.sendFile(path.join(__dirname, './build/index.html'));
});
app.use((err,req, res,next) => {
console.error(err.stack)
res.status(500).send('Something broke!')
});
app.listen(PORT, () => {
console.log(`Server listening on port: ${PORT}`);
});
module.exports = app;