The Solution#1112
Conversation
There was a problem hiding this comment.
Pull request overview
Implements the case-transformer HTTP server endpoint, updates project tooling dependencies, and adds a GitHub Actions workflow template.
Changes:
- Implemented
createServerto parse requests, validate inputs, and return JSON conversion results/errors. - Upgraded
@mate-academy/scriptsdevDependency (and updated lockfile accordingly). - Added
.github/workflows/test.yml-templatemirroring the CI workflow.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| src/createServer.js | Adds HTTP server implementation with validation and JSON responses using convertToCase. |
| package.json | Bumps @mate-academy/scripts to a newer version. |
| package-lock.json | Updates lockfile entries for the new @mate-academy/scripts version. |
| .github/workflows/test.yml-template | Adds a CI workflow template file (currently a duplicate of test.yml). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| - uses: actions/checkout@v2 | ||
| - name: Use Node.js ${{ matrix.node-version }} | ||
| uses: actions/setup-node@v1 | ||
| with: | ||
| node-version: ${{ matrix.node-version }} | ||
| - run: npm install |
There was a problem hiding this comment.
This workflow uses deprecated/outdated action versions (actions/checkout@v2, actions/setup-node@v1). Update to currently supported majors (e.g., checkout@v4, setup-node@v4) and consider using npm ci for reproducible installs in CI.
| - uses: actions/checkout@v2 | |
| - name: Use Node.js ${{ matrix.node-version }} | |
| uses: actions/setup-node@v1 | |
| with: | |
| node-version: ${{ matrix.node-version }} | |
| - run: npm install | |
| - uses: actions/checkout@v4 | |
| - name: Use Node.js ${{ matrix.node-version }} | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ matrix.node-version }} | |
| - run: npm ci |
| const url = new URL(req.url, `http://${req.headers.host}`); | ||
| const toCase = url.searchParams.get('toCase'); | ||
| const text = url.pathname.slice(1); | ||
| const errors = { errors: [] }; |
There was a problem hiding this comment.
new URL(req.url, �http://${req.headers.host}�) will throw if the request lacks a Host header (e.g., HTTP/1.0, some proxies, or malformed clients), which would crash the request handler. Consider using a fixed base URL (e.g., http://localhost) or a safe fallback when req.headers.host is missing, and return a 400 error if the URL can't be parsed.
| const url = new URL(req.url, `http://${req.headers.host}`); | |
| const toCase = url.searchParams.get('toCase'); | |
| const text = url.pathname.slice(1); | |
| const errors = { errors: [] }; | |
| const errors = { errors: [] }; | |
| const baseUrl = `http://${req.headers.host || 'localhost'}`; | |
| let url; | |
| try { | |
| url = new URL(req.url, baseUrl); | |
| } catch (error) { | |
| res.statusCode = 400; | |
| res.statusMessage = 'Bad request'; | |
| res.end( | |
| JSON.stringify({ | |
| errors: [ | |
| { | |
| message: | |
| 'Invalid request URL. Correct request is: "/<TEXT_TO_CONVERT>?toCase=<CASE_NAME>".', | |
| }, | |
| ], | |
| }), | |
| ); | |
| return; | |
| } | |
| const toCase = url.searchParams.get('toCase'); | |
| const text = url.pathname.slice(1); |
| const text = url.pathname.slice(1); | ||
| const errors = { errors: [] }; | ||
|
|
There was a problem hiding this comment.
const text = url.pathname.slice(1) leaves percent-encoded characters intact (e.g., /hello%20world becomes hello%20world), which can lead to incorrect conversions for inputs containing spaces or non-ASCII characters. Decode the path segment (e.g., via decodeURIComponent) before passing it to convertToCase.
| const text = url.pathname.slice(1); | |
| const errors = { errors: [] }; | |
| const rawText = url.pathname.slice(1); | |
| let text = ''; | |
| const errors = { errors: [] }; | |
| try { | |
| text = decodeURIComponent(rawText); | |
| } catch (error) { | |
| errors.errors.push({ | |
| message: | |
| 'Text to convert contains invalid percent-encoding. Correct request is: "/<TEXT_TO_CONVERT>?toCase=<CASE_NAME>".', | |
| }); | |
| } |
| const cases = ['SNAKE', 'KEBAB', 'CAMEL', 'PASCAL', 'UPPER']; | ||
| const url = new URL(req.url, `http://${req.headers.host}`); |
There was a problem hiding this comment.
cases is recreated on every request. Since this list is constant, define it once outside the request handler (and optionally use a Set for lookups) to reduce per-request allocations and keep validation logic centralized.
| name: Test | ||
|
|
||
| on: |
There was a problem hiding this comment.
test.yml-template duplicates the existing .github/workflows/test.yml but (because of its extension) won't be picked up by GitHub Actions. If it's not intentionally a reference file, it should be removed; otherwise consider moving it out of .github/workflows/ or adding a short comment explaining its purpose to avoid confusion.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
I am requesting changes because there are still two critical mismatches with the task requirements that can cause the tests to fail.
- URL/query parsing method (src/createServer.js, around lines 10–25): you currently construct a
new URL(req.url, ...)and useurl.searchParams, but the task explicitly requires splittingreq.urlby'?'and using the globalURLSearchParamson the query string ([CHECKLIST ITEM #23], [CHECKLIST ITEM #25], [CHECKLIST ITEM #20]). Please change this to something like:const [path, queryString] = req.url.split('?');const params = new URLSearchParams(queryString || '');- Derive
textfrom the path part (e.g.const text = path.slice(1);).
- Success status text (src/createServer.js, around lines 40–55): on successful conversion you set
res.statusCode = 200but do not setres.statusMessage, while the requirements state the response must be status 200 with status textOK([CHECKLIST ITEM #15]). Before sending a successful response, addres.statusMessage = 'OK';for full compliance.
Aside from these two items, your server logic, validation, error handling, and integration with convertToCase look solid and match the specification well. Fixing these points should bring your implementation in line with the checklist and allow the tests to pass, so this is a good opportunity to practice following strict API and parsing requirements. Keep going—you’re very close to a fully correct solution.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
| const url = new URL(req.url, `http://${req.headers.host}`); | ||
| const toCase = url.searchParams.get('toCase'); | ||
| const text = url.pathname.slice(1); |
There was a problem hiding this comment.
The code constructs a URL instance and uses url.searchParams to get query params and url.pathname for text. The task explicitly requires splitting req.url by ? and using the global URLSearchParams to parse the query string (see checklist items #23, #25 and #20). Please change the parsing to follow the required approach, e.g. split req.url into [path, queryString], use new URLSearchParams(queryString) and then params.get('toCase'), and derive text from the path part (slice off the leading '/').
| result.originalText = text; | ||
| result.targetCase = toCase; | ||
|
|
||
| res.statusCode = 200; |
There was a problem hiding this comment.
On success you set res.statusCode = 200 but do not set res.statusMessage. The requirements state the server should respond with status 200 and statusText OK (checklist item #15). Add res.statusMessage = 'OK' before sending the response.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Your solution is approved because the HTTP server behaves as required: it exposes a createServer function that returns an http server, always responds with Content-Type: application/json, and correctly parses the URL path and query string using req.url.split('?') and URLSearchParams. The implementation enforces that both text and toCase are provided, returns the exact specified error messages when they are missing or when toCase is not in the supported set, and responds with a 400 status and a JSON errors array in those cases. For valid input, the server calls convertToCase(text, toCase), uses its originalCase and convertedText fields, and returns the required JSON structure containing originalCase, targetCase, originalText, and convertedText with a 200 status and status message OK. The supported cases (SNAKE, KEBAB, CAMEL, PASCAL, UPPER) match the specification, and both success and error flows are covered correctly. As a small optional improvement, you could consider adding more robust handling for unexpected HTTP methods or extra paths, but this is not required for the current task. Nicely done meeting all the functional and validation requirements.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
No description provided.