INEEDAMONITOR/Role-Rally

Questions during development feat: Add APIs 969eeb39c130141d0cca9c9b78c68f955f627ffa

Opened this issue · 0 comments

feat: Add APIs 969eeb3

  • profile:
    • PUT /profile - for updating profile
  • role
    • [id]:
      • GET /role/:id - get Role by role id. This endpoint is for search roles for adding friends. NOTE: the endpoint name may need to be modified
      • DELETE /role/:id - delete role by role id. Verification implemented.
    • GET /role - get role by the cookies
    • DELETE /role/:id - delete role by role id. Verification implemented.
  • user
    • [id]:
      • GET /user/:id - get user by user id
    • GET /user - get user by the cookies

Issue

Problem

During the middleware development, if you resolve the body in the middleware, then you resolve the body in the bottom handler. Error happens.

Fix

Create a request clone to resolve the body.

In middleware

const body = await request.clone().json();

Then you can resolve in the bottom handler

const body = await request.json()

Question

  • Is it a good practice to use middleware?
  • Is there any other way to deal with the lock problem of resolving the body?

Originally posted by @INEEDAMONITOR in #53 (comment)