-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpress.js
48 lines (41 loc) · 1.42 KB
/
express.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
40
41
42
43
44
45
46
47
48
/*===================================
||
|| NodeJS Server with Express Framework
||
===================================*/
/*---------------------------
| Environment Vars
---------------------------*/
require('dotenv').config();
/*---------------------------
| Resources
---------------------------*/
const path = require('path');
const express = require('express');
/*---------------------------
| Express
---------------------------*/
/* Initialize ---------------------------*/
const app = express();
/* JSON support for request response ---------------------------*/
app.use(express.json());
/* Serve the static files from the React app ---------------------------*/
app.use(express.static(path.join(__dirname, 'build')));
/* Heroku :: Redirect to index so React Router Dom can handle routing ----
-----------------------*/
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, '/build/index.html'));
});
/*---------------------------
| Port Management
---------------------------*/
const HEROKU_PORT = process.env.PORT;
const EXPRESS_PORT = process.env.EXPRESS_PORT;
const PORT = (EXPRESS_PORT) ? EXPRESS_PORT : HEROKU_PORT;
const FINAL_PORT = (PORT) ? PORT : 5000; // In case none are provided fall back to 5000
/*---------------------------
| Start the Server
---------------------------*/
app.listen(FINAL_PORT, () => {
console.log('Express Server is up and running. Currently listening on port: ' + FINAL_PORT );
});