0

I have problem with deploying my app to heroku. I have output of react app in built folder (path: /client/build/index.html)

server.js

const express = require('express');
const path = require('path');

const cors = require('cors');
const passport = require('passport');

app.use(express.static(path.resolve(__dirname + '/client/build')));

app.get('*', (req, res) => {
  res.sendFile(path.join(__dirname+'/client/build/index.html'));
});
const port = process.env.PORT || 5000;

const bodyParser = require('body-parser');
const mongoose = require('mongoose');

app.use(bodyParser.urlencoded({extended:false}));
app.use(bodyParser.json());

app.use(cors())
mongoose.connect(process.env.MONGODB_URI)
    .then(() => console.log("success"))
    .catch(err => console.log(err))
app.use(passport.initialize());
require('./config/passport')(passport);


const server = app.listen(port,  function(err) {
  if (err) {
    return;
  } 
  console.log('server listening on port: %s', port);
});

Procfile

web: node server.js

package.json (server) {

  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "node server.js",
    "server": "nodemon server.js",
    "client-install": "npm install --prefix client",
    "client": "npm start --prefix client",
    "dev": "concurrently \"npm run client\" \"npm run server\""
  },
  "author": "",
  "license": "ISC",
 "dependencies": {
    "concurrently": "^4.0.1",
    "express": "^4.16.4",
    "jsonwebtoken": "^8.3.0",
    "mongoose": "^5.3.4",
    "node": "^8.10.0",
    "nodemon": "^1.18.4",
    "passport": "^0.4.0",
    "passport-jwt": "^4.0.0",
    "react-scripts": "1.0.11",
  },
  "devDependencies": {
    "nodemon": "^1.18.4"
  }
}

Is it ok to show my reactApp from build folder? How can I deploy my server? Is it enough to put command in Procfile or should I add for example "heroku-postbuild" in package.json? Thanks for help

PS. After pushing to heroku I got this index.html file, but blank page and server is not working.

2
  • Check through the documentation listed here and follow this tutorial to ensure that your app is setup correctly. Sounds like your react app isn't deployed. Commented Nov 15, 2018 at 11:48
  • Have a look at this answer to see if it helps Commented Nov 15, 2018 at 11:57

1 Answer 1

0

In server.js your app object is not defined as in app = express()

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.