Skip to content

Commit c67f7d3

Browse files
authored
Video-44-Publish-Heroku (#44)
1 parent 1588cea commit c67f7d3

File tree

7 files changed

+31
-6
lines changed

7 files changed

+31
-6
lines changed

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2-
31
# dependencies
42
dist
53
/dist

Procfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: node dist/server.js

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,25 @@ Feel free to take a look at the course preview and enroll if it is along with yo
363363
3. create linear chart for daily sales
364364
4. create pie chart for product categories
365365
44. Publish heroku
366-
1. publish steps
366+
1. Create git repository
367+
2. Create heroku account
368+
3. install Heroku CLI
369+
4. heroku login
370+
5. heroku apps:create <yourname>jsamazona
371+
6. Edit package.json for heroku-prebuild
372+
7. Edit package.json for heroku-postbuild
373+
8. Edit package.json for node engines
374+
9. Create Procfile
375+
10. Edit server.js for PORT
376+
11. Create mongodb atlas database
377+
12. create MongoDB Account
378+
13. open cloud.mongodb.com
379+
14. add new user and save username and password
380+
15. set Network Access to accept all requests
381+
16. Create new database
382+
17. create connection string based on db name and user and password
383+
18. Set Cloud MongoDB connection in heroku env variables
384+
19. Commit and push
367385
45. Product Search Bar
368386
1. create search bar in Header.js
369387
2. add style

backend/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import dotenv from 'dotenv';
33
dotenv.config();
44

55
export default {
6+
PORT: process.env.PORT || 5000,
67
MONGODB_URL: process.env.MONGODB_URL,
78
JWT_SECRET: process.env.JWT_SECRET,
89
PAYPAL_CLIENT_ID: process.env.PAYPAL_CLIENT_ID,

backend/server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ app.use((err, req, res, next) => {
4040
const status = err.name && err.name === 'ValidationError' ? 400 : 500;
4141
res.status(status).send({ message: err.message });
4242
});
43-
app.listen(5000, () => {
43+
app.listen(config.PORT, () => {
4444
console.log('serve at http://localhost:5000');
4545
});

frontend/src/config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
export const apiUrl = 'http://localhost:5000';
1+
export const apiUrl = document.location.href.startsWith('http://localhost')
2+
? 'http://localhost:5000'
3+
: '';

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"start": "nodemon --watch backend --exec babel-node backend/server.js",
88
"build": "rm -rf dest && babel backend -d dist",
99
"serve": "node dist/server.js",
10-
"test": "echo \"Error: no test specified\" && exit 1"
10+
"heroku-prebuild": "cd frontend && npm install --dev",
11+
"heroku-postbuild": "npm run build && cd frontend && npm install && npm run build"
1112
},
1213
"repository": {
1314
"type": "git",
@@ -39,5 +40,9 @@
3940
"eslint-config-prettier": "^6.11.0",
4041
"eslint-plugin-import": "^2.22.0",
4142
"nodemon": "^2.0.4"
43+
},
44+
"engines": {
45+
"node": "12.4.0",
46+
"npm": "6.9.0"
4247
}
4348
}

0 commit comments

Comments
 (0)