-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
29 lines (21 loc) · 770 Bytes
/
Copy pathserver.js
File metadata and controls
29 lines (21 loc) · 770 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
const express = require('express');
const path = require('path');
const jsonServer = require('json-server');
const bodyParser = require('body-parser');
const app = express();
// serve static files from React
app.use(express.static(path.join(__dirname, '/app/build')));
//using body-parser as middleware to handle json req
app.use(bodyParser.json())
// create API endpoints for db
const router = jsonServer.router('reports.json');
const middlewares = jsonServer.defaults();
app.use('/api', router);
// catch-all handler for React code
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname+'/app/build/index.html'));
});
// set up port for app to run on
const port = process.env.PORT || 5000;
app.listen(port);
console.log(`App running on port ${port}`);