Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

11.heroku #12

Draft
wants to merge 4 commits into
base: 10.redux
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"start": "node server/server.js",
"server": "nodemon server/server.js",
"client": "cd client && npm run start",
"dev": "concurrently --kill-others-on-fail \"npm run server\" \"npm run client\""
"dev": "concurrently --kill-others-on-fail \"npm run server\" \"npm run client\"",
"heroku-postbuild": "cd client/src && npm install && npm run build"
},
"repository": {
"type": "git",
Expand Down
13 changes: 13 additions & 0 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const bodyParser = require('body-parser');

const mongoose = require('mongoose');

const path = require('path');

const app = express();
const port = process.env.PORT || 5000;

Expand All @@ -15,6 +17,17 @@ app.use(bodyParser.urlencoded({ extended: true }));
const apis = require("./api");
app.use("/api", apis);

// If in production, then use static frontend build files.
if (process.env.NODE_ENV === 'production') {
// Serve any static files
app.use(express.static(path.join(__dirname, '../client/build')));

// Handle React routing, return all requests to React app
app.get('*', function(req, res) {
res.sendFile(path.join(__dirname, '../client/build', 'index.html'));
});
}

// Connect to Mongo
mongoose.connect(process.env.DB, {
useNewUrlParser: true,
Expand Down