-
Notifications
You must be signed in to change notification settings - Fork 0
/
.instructions2
61 lines (38 loc) · 2.35 KB
/
.instructions2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# MERN JWT Boilerplate
## About This Boilerplate
This setup allows for a Node/Express/React/JWT app which can be easily deployed to Heroku.
The front-end React app will auto-reload as it's updated via webpack dev server, and the backend Express app will auto-reload independently with nodemon.
An article on how the server is setup with JWT can be found [here](https://hptechblogs.com/using-json-web-token-for-authentication/). This has been modified to use a mongo database instead of hardcoded array of users.
The front end has been setup to use JWT as a way of authenticating users and routes. To understand it's structure better please refer to the following article [here](https://hptechblogs.com/using-json-web-token-react/)
Please feel free to modify this code in anyway you see fit for your project. It is a boilerplate setup that tries to make sure you can get something up and running without having to worry about setting up user authentication from scratch.
I highly suggest you read the articles before jumping in so you can have an better understanding of how everything works in the code.
Server-side article and using JWT: https://hptechblogs.com/using-json-web-token-for-authentication/
Front End article on using the JWT on a react application: https://hptechblogs.com/using-json-web-token-react/
## Starting the app locally
Add a .env at the top level of this project.
Then inside of the .env add a SERVER_SECRET set to any value you'd like
```
SERVER_SECRET = 123456
```
Start by installing front and backend dependencies. While in the root directory, run the following command:
```
npm install
```
After all installations complete, run the following command in your terminal:
```
npm start
```
That's it, your app should be running on <http://localhost:3000>. The Express server should intercept any AJAX requests from the client.
## Deployment (Heroku)
### Create a Git Repo
Once you're ready to deploy, start by making sure your project is a git repository. If so, proceed to the next section, otherwise run the following commands in your terminal:
```
git init
git add .
git commit -m "Initial commit"
```
### Deploying
1. Go onto your heroku account and link your repository through the UI
2. Provision a Mongo Database (MongoDB Atlas provides a free sandbox cluster)
3. Add `SERVER_SECRET` and `MONGODB_URI` to the Heroku config.
4. Go back and click "Deploy"