Skip to content

Commit 752db44

Browse files
committed
Prepared for deploy
1 parent 898f525 commit 752db44

File tree

5 files changed

+25
-6
lines changed

5 files changed

+25
-6
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/node_modules
2-
package-lock.json
2+
package-lock.json
3+
/config/keys_dev.js

config/keys.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
module.exports = {
2-
mongoURI: 'mongodb://brad:[email protected]:31725/devconnector',
3-
secretOrKey: 'secret'
4-
};
1+
if (process.env.NODE_ENV === 'production') {
2+
module.exports = require('./keys_prod');
3+
} else {
4+
module.exports = require('./keys_dev');
5+
}

config/keys_prod.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
mongoURI: process.env.MONGO_URI,
3+
secretOrKey: process.env.SECRET_OR_KEY
4+
};

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
"start": "node server.js",
99
"server": "nodemon server.js",
1010
"client": "npm start --prefix client",
11-
"dev": "concurrently \"npm run server\" \"npm run client\""
11+
"dev": "concurrently \"npm run server\" \"npm run client\"",
12+
"heroku-postbuild":
13+
"NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
1214
},
1315
"author": "Brad Traversy",
1416
"license": "MIT",

server.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const express = require('express');
22
const mongoose = require('mongoose');
33
const bodyParser = require('body-parser');
44
const passport = require('passport');
5+
const path = require('path');
56

67
const users = require('./routes/api/users');
78
const profile = require('./routes/api/profile');
@@ -33,6 +34,16 @@ app.use('/api/users', users);
3334
app.use('/api/profile', profile);
3435
app.use('/api/posts', posts);
3536

37+
// Server static assets if in production
38+
if (process.env.NODE_ENV === 'production') {
39+
// Set static folder
40+
app.use(express.static('client/build'));
41+
42+
app.get('*', (req, res) => {
43+
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));
44+
});
45+
}
46+
3647
const port = process.env.PORT || 5000;
3748

3849
app.listen(port, () => console.log(`Server running on port ${port}`));

0 commit comments

Comments
 (0)