Commit 3e7ca3a00e5dcc8b19a12024ebbfd3d443747ff9

Authored by José Maria Villac Pinheiro
1 parent 0a70092a
Exists in master

V. 0.8.3 - Change production check to app.js

Showing 2 changed files with 24 additions and 24 deletions   Show diff stats
@@ -12,6 +12,30 @@ var index = require("./routes/index"); @@ -12,6 +12,30 @@ var index = require("./routes/index");
12 12
13 var app = express(); 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 // view engine setup 39 // view engine setup
16 app.set("views", path.join(__dirname, "views")); 40 app.set("views", path.join(__dirname, "views"));
17 app.set("view engine", "pug"); 41 app.set("view engine", "pug");
@@ -10,30 +10,6 @@ var debug = require('debug')('pg-node:server'); @@ -10,30 +10,6 @@ var debug = require('debug')('pg-node:server');
10 var http = require('http'); 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 - console.log ("NEXUS-__dirname: " + __dirname);  
31 - console.log ("NEXUS-res:" + res);  
32 - res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));  
33 - });  
34 -}  
35 -  
36 -/**  
37 * Define port 13 * Define port
38 */ 14 */
39 var port = normalizePort(process.env.PORT || '5000'); 15 var port = normalizePort(process.env.PORT || '5000');