Repository navigation
Manchester | 26-Jun-SDC | Fithi Teklom | Sprint 3 | Middleware exercise - #127
Fithi-Teklom wants to merge 4 commits into
Conversation
|
|
||
| app.post("/", usernameMiddleware, validateSubjects, (req, res) => { | ||
| res.send( | ||
| `Username: ${req.username}\nSubjects: ${req.body.join(", ")}` |
There was a problem hiding this comment.
We're looking for a response that looks like
You are authenticated as Ahmed.
You have requested information about 4 subjects: Birds, Bats, Lizards, Bees.
Amend this response to reflect that
There was a problem hiding this comment.
We're looking for responses that look a specific way - specified in the coursework prep
Please amend your responses to reflect these instructions
| return res | ||
| .status(400) | ||
| .send("Request body must be a JSON array of strings."); | ||
| } | ||
|
|
There was a problem hiding this comment.
Some good additional reading would be on error handling middleware
this is an express middleware which specifically handles error - and we can use it to specifically point Express to a specific function when a error occurs, skipping anything else.
|
|
||
| req.on("end", () => { | ||
| try { | ||
| const body = JSON.parse(Buffer.concat(chunks).toString("utf8")); |
There was a problem hiding this comment.
What does the Buffer.concat.toString argument do?
Poonam-raj
left a comment
There was a problem hiding this comment.
Few notes to work on here:
- Make sure you're following the response we're expecting. Both middleware examples need their responses edited to reflect what the prep material expects.
- You have nested package files and gitignores within each middleware directory when they are both identical - can we bring this higher up in the module repo to enable us to only run
npm ionce when we load the repo? And reduce how many files we're adding.
Some great express mini apps though, nice work so far
Self checklist
Task code
CYF-1165