Compare View
Commits (2)
Showing
2 changed files
Show diff stats
app.js
... | ... | @@ -12,6 +12,30 @@ var index = require("./routes/index"); |
12 | 12 | |
13 | 13 | var app = express(); |
14 | 14 | |
15 | +/** | |
16 | + * Production version verification. It needs to build for React client. | |
17 | + */ | |
18 | +if (process.env.NODE_ENV === 'production') { | |
19 | + // Express will serve up production assets | |
20 | + // like our main.js file or main.css file! | |
21 | + // this guarantees that expressjs will look | |
22 | + // for specific files in specific directories | |
23 | + console.log ("NEXUS-We are in production..."); | |
24 | + app.use(express.static('../client/build')); // if get request comes in from some route or some file or for anything for my application and we do not understant, then look in some file from this directory to see if some file that matches up the request | |
25 | + | |
26 | + // Express will serve up the index.html file | |
27 | + // if it doesn't recognize the route. | |
28 | + // If something arrives from a route that we do not understand, | |
29 | + // look at the index.htm file in the client directory | |
30 | + const path = require('path'); | |
31 | + app.get('*', (req, res) => { | |
32 | + console.log ("NEXUS-__dirname: " + __dirname); | |
33 | + console.log ("NEXUS-res:" + res); | |
34 | + res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html')); | |
35 | + }); | |
36 | +} | |
37 | + | |
38 | + | |
15 | 39 | // view engine setup |
16 | 40 | app.set("views", path.join(__dirname, "views")); |
17 | 41 | app.set("view engine", "pug"); | ... | ... |
bin/www
... | ... | @@ -10,28 +10,6 @@ var debug = require('debug')('pg-node:server'); |
10 | 10 | var http = require('http'); |
11 | 11 | |
12 | 12 | /** |
13 | - * Production version verification. It needs to build for React client. | |
14 | - */ | |
15 | -var express = require("express"); | |
16 | -if (process.env.NODE_ENV === 'production') { | |
17 | - // Express will serve up production assets | |
18 | - // like our main.js file or main.css file! | |
19 | - // this guarantees that expressjs will look | |
20 | - // for specific files in specific directories | |
21 | - console.log ("NEXUS-We are in production..."); | |
22 | - app.use(express.static('../client/build')); // if get request comes in from some route or some file or for anything for my application and we do not understant, then look in some file from this directory to see if some file that matches up the request | |
23 | - | |
24 | - // Express will serve up the index.html file | |
25 | - // if it doesn't recognize the route. | |
26 | - // If something arrives from a route that we do not understand, | |
27 | - // look at the index.htm file in the client directory | |
28 | - const path = require('path'); | |
29 | - app.get('*', (req, res) => { | |
30 | - res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html')); | |
31 | - }); | |
32 | -} | |
33 | - | |
34 | -/** | |
35 | 13 | * Define port |
36 | 14 | */ |
37 | 15 | var port = normalizePort(process.env.PORT || '5000'); | ... | ... |