Repository navigation
Expand file tree
/
Copy pathapp.js
More file actions
68 lines (63 loc) · 1.55 KB
/
Copy pathapp.js
File metadata and controls
68 lines (63 loc) · 1.55 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const express = require('express');
const app = express();
const morgan = require('morgan');
const cors = require('cors');
const path = require('path');
app.use(cors());
app.use(morgan('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.get('/api/contacts', (req, res, next) => {
res.json([
{
name: 'Jane',
email: '[email protected]',
phone: '555-555-5555',
department: 'Engineering',
position: 'Software Engineer'
},
{
name: 'John',
email: '[email protected]',
phone: '555-555-5555',
department: 'IT',
position: 'Network Admin'
},
{
name: 'Jill',
email: '[email protected]',
phone: '555-555-5555',
department: 'Marketing',
position: 'Marketing Manager'
},
{
name: 'Jack',
email: '[email protected]',
phone: '555-555-5555',
department: 'HR',
position: 'HR Manager'
},
{
name: 'Joe',
email: '[email protected]',
phone: '555-555-5555',
department: 'Sales',
position: 'Sales Manager'
},
{
name: 'Josephine',
email: '[email protected]',
phone: '555-555-5555',
department: 'Finance',
position: 'Finance Manager'
},
]);
})
// serve client app
app.use(express.static('dist'));
// for react router: send back index.html when requesting any route
// react-router will pick up the route and render the correct component
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'dist/index.html'));
});
module.exports = app;