title: Accessing GET routes inside React App on Express Server in production
body: <p>Have followed along with one of Stephen Girder's videos on Udemy and wanted to implement some FaceBook login flow to my own app.</p>
  
  <p>But I can't seem to access the app.get routes in production mode. Everything works fine on localhost and development. When I go to /auth/facebook all I get is a blank screen. </p>
  
  <p>I am using react-router-dom. I am trying various techniques such as socket.io but just can't seem to get it working :( </p>
  
  <p>Server index.js file</p>
  
  <pre><code>/* global __dirname process env */
  const mongoose = require('mongoose');
  const express = require('express');
  const cookieSession = require('cookie-session');
  const keys = require('./server/config/keys');
  const bodyParser = require('body-parser');
  const auth = require('./server/routes/auth');
  const passport = require('passport');
  const https = require('https');
  const cors = require('cors')
  const socketio = require('socket.io')
  const authRouter = require('./server/lib/auth.router')
  const passportInit = require('./server/lib/passport.init')
  const { SESSION_SECRET, CLIENT_ORIGIN } = require('./config')
  const fs = require('fs');
  const pug = require('pug');
  const path = require('path');
  const gulp = require('gulp');
  
  let server;
  
  mongoose
      .connect(keys.mongoURI)
      .then(() =&gt; console.log('connection successful'))
      .catch(err =&gt; console.log(err));
  
  require('./server/models/SimpleTask');
  require('./server/models/simpleLongTask');
  require('./server/models/DailyJournals');
  require('./server/models/Tracks');
  require('./server/models/Hats');
  require('./server/models/DailyTaskList');
  require('./server/models/RepeatTask');
  require('./server/models/RedueTask');
  require('./server/models/TrackTree');
  
  // used for development purposes.
  const morgan = require('morgan');
  const options = {
      key: fs.readFileSync('./server/keys/server.key'),
      cert: fs.readFileSync('./server/keys/server.crt'),
  };
  
  const app = express();
  
  const PORT = process.env.PORT || 5000;
  // If we are in production we are already running in https
  if (process.env.NODE_ENV === 'production') {
    server = http.createServer(app)
  }
  // We are not in production so load up our certificates to be able to
  // run the server in https mode locally
  else {
    const certOptions = {
          key: fs.readFileSync('./server/keys/server.key'),
          cert: fs.readFileSync('./server/keys/server.crt')
    }
    server = https.createServer(certOptions, app)
  }
  app.use(morgan('dev'));
  
  app.use(bodyParser.json());
  app.use(
      cookieSession({
          maxAge: 30 * 24 * 60 * 60 * 1000,
          keys: 'dashgkjlahgfkljashfkjasdflkhasdfjklh'
      })
  );
  app.use(cors({
    origin: CLIENT_ORIGIN
  }))
  const io = socketio(server)
  app.set('io', io)
  
  // app.use(localJWT.initialize());
  require('./server/routes/book')(app);
  require('./server/routes/auth')(app, passport);
  require('./server/routes/loginRoutes')(app, passport);
  require('./server/routes/tasksRoutes')(app);
  require('./server/routes/calendarRoutes')(app);
  require('./server/routes/trackRoutes')(app);
  // require('./server/routes/frontEnd')(app);
  
  
  if (process.env.NODE_ENV === 'production') {
      // Express will serve up production assets.
      // Like our main.js file, or main.css file
      app.use(express.static('client/build'));
      // Express will serve up the index.html file if it doesn't know the route....
      const path = require('path');
      app.get('*', (req, res) =&gt; {
          res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));
      });
  }
  //
  // // reload code
  // app.use(express.static('./dist/', {
  //     extensions: ['html', 'htm']
  // }));
  
  app.get('/wake-up', (req, res) =&gt; res.send(''))
  server.listen(process.env.PORT || 5000, () =&gt; {
    console.log('listening...')
  })
  </code></pre>
  
  <p>Login Routes. </p>
  
  <pre><code>const mongoose = require('mongoose');
  const passport = require('passport');
  const express = require('express');
  
  const User = require('../models/User');
  const jwt = require('jsonwebtoken');
  
  const settings = require('../config/settings');
  require('../services/facebookPassport')(passport);
  
  module.exports = (app, passport) =&gt; {
      // send to facebook to do the authentication
      app.get(
          '/auth/facebook',
          passport.authenticate('facebook', { scope: 'email' })
      );
      app.get(
          '/auth/facebook/callback',
          passport.authenticate('facebook', {
              session: false
          }), (req, res) =&gt; {
              const token = jwt.sign(req.user.toJSON(), settings.secret);
              res.cookie('jwtToken', token);
              res.redirect('/social_auth');
          }
      );
      app.post(
          '/connect/local',
          passport.authenticate('local-signup', {
              successRedirect: '/profile', // redirect to the secure profile section
              failureRedirect: '/connect/local', // redirect back to the signup page
              failureFlash: true // allow flash messages
          })
      );
      // facebook ------- authorization.
      app.get(
          '/connect/facebook',
          passport.authorize('facebook', {
              scope: ['public_profile', 'email']
          })
      );
      // handle the callback after facebook has authorized the user
      app.get(
          '/connect/facebook/callback',
          passport.authorize('facebook', {
              successRedirect: '/profile',
              failureRedirect: '/'
          })
      );
      // route middlewarer to ensure user is logged in before authorization
      function isLoggedIn(req, res, next) {
          if (req.isAuthenticated()) return next();
          res.redirect('/');
      }
  };
  </code></pre>