West Midlands | 26 March SDC | Iswat Bello | Sprint 3 | Middleware exercises#93
Open
Iswanna wants to merge 8 commits into
Open
West Midlands | 26 March SDC | Iswat Bello | Sprint 3 | Middleware exercises#93Iswanna wants to merge 8 commits into
Iswanna wants to merge 8 commits into
Conversation
- 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Learners, PR Template
Self checklist
Changelist
In this PR, I created two directories to demonstrate different approaches to Express middleware:
X-Usernameheader, and another (arrayMiddleware) manually handles raw data streams to parse and validate aJSONarray of strings.express.json()middleware. This version includes a streamlinedvalidateArraymiddleware to ensure the parsed body meets specific requirements.