Skip to content

Birmingham | 26-SDC-Mar | Chioma Okeke | Sprint 3 | Middleware Exercises#98

Open
JanefrancessC wants to merge 12 commits into
CodeYourFuture:mainfrom
JanefrancessC:middlewares
Open

Birmingham | 26-SDC-Mar | Chioma Okeke | Sprint 3 | Middleware Exercises#98
JanefrancessC wants to merge 12 commits into
CodeYourFuture:mainfrom
JanefrancessC:middlewares

Conversation

@JanefrancessC

Copy link
Copy Markdown

Learners, PR Template

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

Changelist

Added two Express server middleware implementations.

custom-middleware

Implements two custom Express middlewares:

  • extractUsername reads the X-Username header and attaches it to req.username.
  • parseJsonArrayBody manually collects incoming request body chunks, parses them as JSON, and validates that the result is an array of strings.

This version demonstrates low-level request handling without relying on Express built-in body parsing.

off-the-shelf-middleware

Replaces the custom body parsing middleware with express.json().

This version highlights a key difference in Express behaviour: express.json() only processes requests when the Content-Type: application/json header is present. As a result, earlier curl requests using --data without explicitly setting the content type were not parsed correctly.

@github-actions

This comment has been minimized.

@JanefrancessC JanefrancessC added 📅 Sprint 3 Assigned during Sprint 3 of this module Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Module-Decomposition The name of the module. labels Jun 12, 2026
@github-actions

This comment has been minimized.

@github-actions github-actions Bot removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Jun 12, 2026
@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

@JanefrancessC JanefrancessC changed the title Birmingham | 26-SDC-Mar | Chioma Okeke | Middlewares Birmingham | 26-SDC-Mar | Chioma Okeke | Sprint 3 | Middleware Exercises Jun 12, 2026
@JanefrancessC JanefrancessC added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Jun 12, 2026

@LonMcGregor LonMcGregor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good work on this task, I have a couple of comments however.

Comment thread chat-app/README.md

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Did you mean to commit this change to this file here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

No, it was an error. That's why i deleted the file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you fix it so that this file is no longer listed in the "changed files" for this pull request?

// Authenticate if a username is provided
const authLine = req.username
? `You're authenticated as ${req.username}`
: `You're not authenticated!`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If the user is not authenticated, should the app be returning anything?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

For this exercise, if X-username isn't present, req.username is set to null. My understanding of it is that the middleware will recognise authenticated users but not enforce authentication.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Typically if someone is not authorised or not authenticated we might want the app to behave a bit differently. Here is says not authenticated but still returns data. Is there any alternative approach you could take?

@LonMcGregor LonMcGregor added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Module-Decomposition The name of the module. Reviewed Volunteer to add when completing a review with trainee action still to take. 📅 Sprint 3 Assigned during Sprint 3 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants