title: Vue + Express app on heroku not using the SPA in server/public folder
body: <p>My app is running on heroku and the routes send me JSON files, but what I need is to use the SPA that is in my ./server/public folder as index.html.
  When I open the heroku app it send me the JSON file that is sent from the "/" route, but I need it to use the Vue SPA, because of what I did in my front-end client if for some reason you go to a route that doesn't exists it does redirect me to my "/forum" route with the front-end client, but any other route that exists will not work, it will keep sending the JSON of that route.  </p>
  
  <p>app/server.js</p>
  
  <pre><code>const express = require('express');
  const path = require('path');
  const bodyParser = require('body-parser');
  const expressValidator = require("express-validator");
  const flash = require('connect-flash');
  const mongoose = require('mongoose');
  const cors = require("cors");
  const config = require("./config/database");
  if(process.env.NODE_ENV !== "production") require('dotenv').config();
  
  mongoose.connect(config.database, { useNewUrlParser: true, useFindAndModify: false });
  
  let db = mongoose.connection;
  
  db.once("open", () =&gt; {
      console.log("Connected to MongoDB Atlas");
  });
  
  db.on("error", (err) =&gt; {
      console.log(err);
  });
  
  const app = express();
  
  //Body-parser
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: true }));
  
  app.use(cors());
  app.use(expressValidator());
  app.use(flash());
  app.use(cors());
  
  require("./passport")
  
  //Routes
  const home = require("./routes/home.js");
  const forum = require('./routes/forum.js');
  const ranking = require('./routes/ranking.js');
  const profile = require('./routes/profile.js');
  
  // Routing
  app.use("/", home);
  app.use("/forum", forum);
  app.use("/profile", profile);
  app.use("/ranking", ranking);
  
  // Handle production build
  if (process.env.NODE_ENV === "production") {
      app.use(express.static(__dirname + '/public/'));
      app.get(/.*/, (req, res) =&gt; { res.sendFile(__dirname + '/public/index.html') });
  }
  
  // PORT
  const port = process.env.PORT || 3000;
  app.listen(port, () =&gt; {
      console.log(`Server listening on port ${port}`)
  });
  
  </code></pre>