You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: readme.md
+8-9Lines changed: 8 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,7 +28,7 @@ This is a simple SPA built using [Koa](http://koajs.com/) (2.3) as the backend a
28
28
- Prettier
29
29
- Babel
30
30
- PM2
31
-
- MySQL
31
+
- MySQL with Knex
32
32
- log4js
33
33
- And more...
34
34
@@ -41,11 +41,14 @@ npm install
41
41
# serve using nodemon with hot reload
42
42
npm run watch
43
43
44
-
# build for production with prettier
44
+
# build for production with prettier and babel
45
45
npm run build
46
46
47
47
# serve in production using the pm2 ecosystem.json file
48
48
npm run start-production
49
+
50
+
# run prettier on the project
51
+
npm run pretty
49
52
```
50
53
51
54
## General Information
@@ -67,7 +70,7 @@ As mentioned in the frontend code, the user authentication process is this:
67
70
- User create an account
68
71
- User logs in
69
72
- The server sends and `accessToken` and a `refreshToken` back
70
-
- We take the `accessToken` and decoded it using `jwt-decode`. This gets us the logged in user's information. We stick this in the Vuex variable `user`. Then we store the `refreshToken` amd `accessToken`.
73
+
- We take the `accessToken` and decode it using `jwt-decode`. This gets us the logged in user's information. We stick this in the Vuex variable `user`. Then we store the `refreshToken` amd `accessToken`.
71
74
- Each protected endpoint will be expecting you to attach the `accessToken` you have to the call (using Authentication: Bearer). After a short amount of time, the server will respond with `401 TOKEN EXPIRED`. When you see this - that means you need to send your `refreshToken` and `user.email` to the endpoint that deals with `accessToken` refreshing. Once you do that, you'll received a brand new `accessToken` and `refreshToken`.
72
75
- Repeat the process as needed.
73
76
@@ -79,11 +82,11 @@ The `src` folder is the heart of the program. I'll go over its subfolders now.
79
82
80
83
### controllers
81
84
82
-
We use controllers to keep our router thin. The controller's responsibility is to manage the request body and make sure it's nice and clean when it eventually gets sent to a `model` to make database calls. There are two controller files present - one for user signup/login/forgot... and one for notes.
85
+
We use controllers to keep our router thin. The controller's responsibility is to manage the request body and make sure it's nice and clean when it eventually gets sent to a `model` to make database calls. There are two controller files present - one for user signup/login/forgot... and one for notes. Note: the `UserActionController.js` is a little different then normal controllers, as I believe the actions of a user signup/login/forgot/reset are seperate from the normal actions for a user - so that's why `UserActionController.js` in written in a more *functional* way.
83
86
84
87
### db
85
88
86
-
Here is our database setup. This project uses Knex to manage migarations and execute queries. I initially wrote raw SQL queries for the program, but the need for a migrations maanager pushed me towards an ORM for the MySQL database. Knex is awesome - very powerful, easy to use and make queries, and the migarations are nice to have for sure - especially for testing.
89
+
Here is our database setup. This project uses Knex to manage migrations and execute queries. I initially wrote wrote all the MySQL calls using raw SQL, but the need for a migrations maanager pushed me towards an ORM for the MySQL database. Knex is awesome - very powerful, easy to use and make queries, and the migrations are nice to have for sure - especially for testing.
87
90
88
91
### middleware
89
92
@@ -97,10 +100,6 @@ Our models folder contains two model files - one for users and one for notes. Th
97
100
98
101
Very simple - here are our routes. I've broken it down into two files - this keeps things in control. Each route is nice and thin - all it's doing is calling a controller. Some routes are using that jwt middleware I mentioned earlier. Koa make it really nice and easy to add middleware to a route. Very cool.
99
102
100
-
### sql
101
-
102
-
I provided the sql code here you'll need when creating your database. I was hoping to find a nice database-migration library for node - but unfortunately I came up empty-handed. I tried TJ's - but I think it's not really supported anymore - didn't work for me using the latest Node and ES6/7 syntax. I'm keeping my eye out for one - let me know if you use one you like.
0 commit comments