-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
53 lines (39 loc) · 1.64 KB
/
server.js
File metadata and controls
53 lines (39 loc) · 1.64 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
require('dotenv').config();
const express = require("express");
const bodyParser = require("body-parser");
const cookieParser = require("cookie-parser");
const PORT = process.env.PORT || 8080;
//conditional for child_process working under cross platform conditions
const start = (process.platform == 'darwin'? 'open': process.platform == 'win32'? 'start': 'xdg-open');
const app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(cookieParser());
require("./routes/api-routes.js")(app);
//CONFIGURE FOR HEROKU DEPLOYMENT
if (process.env.NODE_ENV === 'production') {
// Serve any static files
app.use(express.static('client/build'));
// Handle React routing, return all requests to React app
app.get('/', function(req, res) {
res.sendFile('client/build', 'index.html');
});
//listen for requests
app.listen(PORT, () => {
if (process.env.NODE_ENV_PRODUCTION_TEST === 'true') {
//opens up localhost address on browser
require('child_process').exec(`${start} http://localhost:${PORT}/`);
console.log(`Server is running on port ${PORT} in production mode.`);
}else {
//opens up production address on browser
require('child_process').exec(`${start} https://portafoglioreact.onrender.com/`);
console.log(`Server is running on port ${PORT} in production address.`);
console.log(`PRODUCTION TEST (env variable) = ${process.env.NODE_ENV_PRODUCTION_TEST || 'NONE'} `);
}
});
}else{
//listen for requests in development mode
app.listen(PORT, () =>{
console.info(`server has started on ${PORT} in development mode`);
});
};