Skip to content

Sheffield | 25-SDC-Nov | Hassan Osman | Sprint 3 | Middleware#71

Open
HassanOHOsman wants to merge 17 commits intoCodeYourFuture:mainfrom
HassanOHOsman:feature/middlewares
Open

Sheffield | 25-SDC-Nov | Hassan Osman | Sprint 3 | Middleware#71
HassanOHOsman wants to merge 17 commits intoCodeYourFuture:mainfrom
HassanOHOsman:feature/middlewares

Conversation

@HassanOHOsman
Copy link

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

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.

@HassanOHOsman HassanOHOsman added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. 📅 Sprint 3 Assigned during Sprint 3 of this module labels Feb 13, 2026
@OracPrime OracPrime added the Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. label Feb 17, 2026
Copy link

@OracPrime OracPrime left a comment

Choose a reason for hiding this comment

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

Heading in the right direction, but a few changes needed

@@ -0,0 +1,66 @@
// Middleware 1 looks for a header with name "X-Username"

Choose a reason for hiding this comment

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

You need a .gitignore file: you really don't want to be checking node_modules into git

Copy link
Author

Choose a reason for hiding this comment

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

I was meaning to ignore it, silly me! totally forgot. Anyway, it's been ignored now. Thank you :)

const PORT = 3000;

app.use(usernameMiddleware);
app.use(postBodyAsJsonMiddleware);

Choose a reason for hiding this comment

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

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)

Copy link
Author

Choose a reason for hiding this comment

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

Good to know - thank you! Changed accordingly and tested it and got expected output.

} else {
responseToClient = "You are not authenticated.";
}

Choose a reason for hiding this comment

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

Aren't you missing the second half of the response here?

Copy link
Author

Choose a reason for hiding this comment

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

Added.

@OracPrime OracPrime 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. Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Feb 17, 2026
@HassanOHOsman HassanOHOsman added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Feb 17, 2026
Copy link

@OracPrime OracPrime left a comment

Choose a reason for hiding this comment

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

All sorted, well done.

@OracPrime OracPrime added Reviewed Volunteer to add when completing a review with trainee action still to take. Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Feb 17, 2026
@HassanOHOsman HassanOHOsman removed the Reviewed Volunteer to add when completing a review with trainee action still to take. label Feb 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Complete Volunteer to add when work is complete and all review comments have been addressed. 📅 Sprint 3 Assigned during Sprint 3 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments