Skip to content

West Midlands | 26 March SDC | Iswat Bello | Sprint 3 | Middleware exercises#93

Open
Iswanna wants to merge 8 commits into
CodeYourFuture:mainfrom
Iswanna:middleware-exercises
Open

West Midlands | 26 March SDC | Iswat Bello | Sprint 3 | Middleware exercises#93
Iswanna wants to merge 8 commits into
CodeYourFuture:mainfrom
Iswanna:middleware-exercises

Conversation

@Iswanna
Copy link
Copy Markdown

@Iswanna Iswanna commented Jun 5, 2026

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

In this PR, I created two directories to demonstrate different approaches to Express middleware:

  • two-custom-written-middlewares.js: Features two custom-written middlewares. One extracts a username from the X-Username header, and another (arrayMiddleware) manually handles raw data streams to parse and validate a JSON array of strings.
  • off-the-shelf-middleware.js: Refactors the previous app to use the built-in express.json() middleware. This version includes a streamlined validateArray middleware to ensure the parsed body meets specific requirements.

Iswanna added 8 commits May 9, 2026 23:26
- Exclude node_modules/ and package-lock.json from version control
- Ignore environment variables (.env) and system files (.DS_Store)
- Exclude build artifacts (dist/, build/) and log files (*.log)
- Ignore VS Code workspace settings (.vscode/)
- Reduce repository size and prevent committing sensitive data
- Add username middleware that reads X-username header and sets req.username (or null).
- Add array middleware that accumulates request bytes, parses JSON, validates it's an array of strings, assigns req.body or returns 400 on invalid input.
- Add package.json with Express dependency.
Enable ES module syntax (import/export) for the project by setting "type": "module" in package.json.
…dd route and start server

- Create Express app instance and use PORT from process.env with 3000 fallback.
- Add try/catch around JSON.parse in array middleware and return 400 on invalid JSON.
- Add POST "/" route that composes response using usernameMiddleware and arrayMiddleware.
- Start server with app.listen.
- Rename middleware-exercise/app.js to middleware-exercise/two custom-written middlewares.js
- Clarifies that the file contains two custom middleware implementations
- Change condition in two-custom-written-middlewares.js from
  MessageCount <= 1 to MessageCount === 1 so "subject" is used only
  when there is exactly one item (zero now uses "subjects").
- Add off-the-shelf-middleware.js: create Express app and listen on PORT (env fallback to 3000).
- Add username middleware (reads X-username header into req.username).
- Add validateArray middleware (ensures JSON body is an array of strings; returns 400 on invalid input).
- Add POST "/" route that composes a response using the middlewares and starts the server.
- Add README.md describing how to run the custom and off-the-shelf middleware demos.
- Document key concepts: middleware pattern, manual parsing vs express.json, env PORT fallback, and process management.
- Include curl examples for valid and invalid requests and note default port 3000.
@Iswanna Iswanna 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 5, 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. 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant