Koa implementation: Comment management background
Do you even need to look at the back end with this
Original intention of writing this: Reviewing the Node stack, the reason why KOA is used instead of Express is because Express does not handle asynchronous functions very well, whereas KOA has a natural advantage when dealing with asynchronous functions because KOA’s source code is reprocessed through dispatch and Promsie is inside dispatch. In addition, this project does not contain the display page, the interface call success directly look at the database on the line, I believe that you are able to achieve their own gorgeous front-end page
The project address
> GitHub MiyaHub
Technology stack
- KOA: Node development framework
- Env files using vue-cli or create-react-app are familiar with this configuration
- Jsonwebtoken: Implements JWT
- Koa-bodyparser: Parses content-Type: Application/JSON data
- Koa-router: splits services
- Mysql2 :node connects to the database
Project characteristics
- When a user registers, MD5 salt encryption of the password can be ported directly to the real project
- Front-end engineering: dynamic parameters in the project are written in the. Env file, and the project structure code is written in accordance with the front-end development specifications
- JWT is implemented and can be directly ported to actual development
- In our actual scenario business development, we are also token validators
Project business process
- User registration
- User login: After a user successfully logs in, the system returns the user name, password, and token
- In subsequent business processes, you need to carry this token
- Publish dynamics (put tokens into the Header Authorization field)
- Comment on published developments
- Reviews editor
- Comments to delete
JWT
A token is required in the service scenario after login
Build steps
-
Mysql > create Mysql database locally
-
Insert the beans_flight.sql statement from the SQL folder into the database
-
Modify the. Env database configuration file in the root directory (for your own database configuration)
Start the project
NPM run start or YARN start
The Debugger to debug
If you are developing using Vscode, you can debug the runtimeExecutable directly using the launch.json configured in the project
API interface
- Registered interface
Interface to invoke http://localhost:8000/users/ post way if the call is successful return values {returns the following structure "fieldCount" : 0, "affectedRows" : 1, "insertId" : 4, "info": "", "serverStatus": 2, "warningStatus": 0 }
- Login interface
/ / interface to invoke http://localhost:8000/login post way / / if the call is successful, returns the following the return value of the interface {" id ": 3," name ":" front-end teasing fly ", "token" : "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MywibmFtZSI6IuWJjeerr-mAl-mAl-mjniIsImlhdCI6MTYzMTc3MDk3NCwiZXhwIjoxNjMxOD U3Mzc0fQ.TDTTW2f7nBX4Hrbtii40f8xRCbK6QFl05WuCWB2yh0nwYLa1pMCXz6RkhSPspDyb7iyqYirGcAdZQ2_yDrg42yBsEhyQPijRi8rQdtssnDR0cVa REnF5CMveQndyjRBOldcT8yH6TDAQVqkX8PR95dwLO5dtxkK9-VgU7ZbSAoo" }
- Dynamic publishing interface
/ / / / interface ways that post call http://localhost:8000/moment into the refs for {" name ":" front-end teasing fly ", "password" : "123456", "content" : "Kuaishou, up until the Spring Festival, this name was only one app on Zhihu. Of course, it wasn't the only one, but it didn't matter. During the Spring Festival, I return to the country's rural areas, rural poor signal, can barely see WeChat, the village has a public WiFi, at least you can connect to the Internet, a group of young men is there WiFi, rub in dialect is commenting on a beauty body beautiful, someone do stupid things again, which the game host more severe, coarse language, voice also very awkard. I didn't like them at all, but I watched the drama silently with my phone beside me, and I didn't dare to turn the volume too high for fear of hurting my ears. {"fieldCount": 0, "affectedRows": 1, "insertId": 21, "info": ", "serverStatus": 2, "warningStatus": 0 }
- Comments on the interface
Call / / / / interface to PATCH way to dynamic id of the joining together to the url http://localhost:8000/comment/4 / / {refs "content" : {"fieldCount": 0, "affectedRows": 1, "insertId": 0, "info": "Rows matched: 1 Changed: 0 Warnings: 0", "serverStatus": 2, "warningStatus": 0, "changedRows": 0 }
- Comment reply interface
/ / interface to call / / post way to dynamic id of the joining together to the url http://localhost:8000/comment/4/reply / / {refs "momentId" : 19, / / comment on the id of the "content" : {"fieldCount": 0, "affectedRows": 1, "insertId": 0, "info": "Rows matched: 1 Changed: 0 Warnings: 0", "serverStatus": 2, "warningStatus": 0, "changedRows": 0 }
- Comment delete interface
/ / interface ways that delete call / / want to delete the comment id spliced into the url http://localhost:8000/comment/6 / / if the call is successful, returns the following structure return value {" fieldCount ": 0, "affectedRows": 1, "insertId": 0, "info": "Rows matched: 1 Changed: 0 Warnings: 0", "serverStatus": 2, "warningStatus": 0, "changedRows": 0 }