-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
36 lines (28 loc) · 859 Bytes
/
server.js
File metadata and controls
36 lines (28 loc) · 859 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
const express = require('express');
const cors = require('cors');
const path = require('path');
const api = require('./api/routes/index.js');
const app = express();
const port = process.env.PORT || 5000;
app.use((req, res, next) => {
console.log(`Request_Endpoint: ${req.method} ${req.url}`);
next();
});
app.use(express.json());
app.use(express.urlencoded({
extended: true
}));
app.use(cors());
app.use('/api/v1/', api);
if (process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'staging') {
app.use(express.static(path.join(__dirname, 'client/build')));
app.get('*', function (req, res) {
res.sendFile(path.join(__dirname, 'client/build', 'index.html'));
});
};
app.get('*', (req, res) => {
res.status(404).json({
msg: 'Not Found'
});
});
app.listen(port, () => console.log(`BACK_END_SERVICE_PORT: ${port}`));