Skip to content

Manchester | 26-Jun-SDC | Fithi Teklom | Sprint 3 | Middleware exercise - #127

Open
Fithi-Teklom wants to merge 4 commits into
CodeYourFuture:mainfrom
Fithi-Teklom:feature/middleware_exercise
Open

Fithi-Teklom wants to merge 4 commits into
CodeYourFuture:mainfrom
Fithi-Teklom:feature/middleware_exercise

Conversation

@Fithi-Teklom

Copy link
Copy Markdown

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Task code

CYF-1165

@Fithi-Teklom Fithi-Teklom added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 3, 2026
@Poonam-raj Poonam-raj added Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Oct 13, 2026

app.post("/", usernameMiddleware, validateSubjects, (req, res) => {
res.send(
`Username: ${req.username}\nSubjects: ${req.body.join(", ")}`

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're looking for responses that look a specific way - specified in the coursework prep

Please amend your responses to reflect these instructions

Comment on lines +21 to +25
return res
.status(400)
.send("Request body must be a JSON array of strings.");
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does the Buffer.concat.toString argument do?

@Poonam-raj Poonam-raj left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 i once when we load the repo? And reduce how many files we're adding.

Some great express mini apps though, nice work so far

@Poonam-raj Poonam-raj added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Reviewed Volunteer to add when completing a review with trainee action still to take.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants