Sheffield | 25-SDC-Nov | Hassan Osman | Sprint 3 | Middleware#71
Sheffield | 25-SDC-Nov | Hassan Osman | Sprint 3 | Middleware#71HassanOHOsman wants to merge 17 commits intoCodeYourFuture:mainfrom
Conversation
…e control is handed over by a second middleware
…e handdled by 1 response to the client
…re no longer relevant before adding off-the-shelf body parsing middleware
OracPrime
left a comment
There was a problem hiding this comment.
Heading in the right direction, but a few changes needed
| @@ -0,0 +1,66 @@ | |||
| // Middleware 1 looks for a header with name "X-Username" | |||
There was a problem hiding this comment.
You need a .gitignore file: you really don't want to be checking node_modules into git
There was a problem hiding this comment.
I was meaning to ignore it, silly me! totally forgot. Anyway, it's been ignored now. Thank you :)
custom-middlewares/index.js
Outdated
| const PORT = 3000; | ||
|
|
||
| app.use(usernameMiddleware); | ||
| app.use(postBodyAsJsonMiddleware); |
There was a problem hiding this comment.
This will use this middleware for every request. At the moment we only have one request, so it will still work, but to encourage good habits I'm going to ask you to move this so that it only applies to the request you define at line 43. The username middleware is one that is likely to be more widely used, so I'm happy for that to stay global (not least because it doesn't cause an error if it doesn't find the header)
There was a problem hiding this comment.
Good to know - thank you! Changed accordingly and tested it and got expected output.
| } else { | ||
| responseToClient = "You are not authenticated."; | ||
| } | ||
|
|
There was a problem hiding this comment.
Aren't you missing the second half of the response here?
… every request it runs only when relevany (POST )
Self checklist
In this pull request I created two Express apps: one with two custom middleware and one using a built-in JSON parsing, both handle username and subjects from POST requests.