Skip to content

Commit f06da16

Browse files
author
Esterling Accime
committed
adding message
1 parent 59618f6 commit f06da16

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"main": "server.js",
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1",
8-
"start": "node server.js"
8+
"start": "node server.js",
9+
"heroku-postbuild": "cd client && npm install && npm run build"
910
},
1011
"keywords": [],
1112
"author": "",

server.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ const routes = require('./routes');
1111
// Define Global Variables
1212
const app = express();
1313
const log = console.log;
14-
const PORT = 8080;
14+
const PORT = process.env.PORT || 8080; // Step 1
1515

1616

17-
mongoose.connect('mongodb://localhost/my_database', {
17+
// Step 2
18+
mongoose.connect( process.env.MONGODB_URI || 'mongodb://localhost/my_database', {
1819
useNewUrlParser: true
1920
});
2021

@@ -23,6 +24,14 @@ app.use(bodyParser.json());
2324
app.use(bodyParser.urlencoded({ extended: false }));
2425
app.use('/', routes);
2526

27+
// Step 3
28+
if (process.env.NODE_ENV === 'production') {
29+
app.use(express.static( 'client/build' ));
30+
31+
app.get('*', (req, res) => {
32+
res.sendFile(path.join(__dirname, 'client', 'build', 'index.html')); // relative path
33+
});
34+
}
2635

2736
app.listen(PORT, () => {
2837
log(`Server is starting at PORT: ${PORT}`);

0 commit comments

Comments
 (0)