Skip to content

[DC-1475] Upgrade JsonServer to Node.js 24 LTS to address Node.js 20 EOL and security vulnerabilities - #22

Open
GNSubrahmanyam wants to merge 11 commits into
releasefrom
DC-1475
Open

GNSubrahmanyam wants to merge 11 commits into
releasefrom
DC-1475

Conversation

@GNSubrahmanyam

Copy link
Copy Markdown
Member

No description provided.

…server-local.js

chore: add Postman collection for DoSelect JSON Server with comprehensive CRUD tests and query patterns

refactor: restructure server code to use src/app.js for better organization and data handling

fix: improve data serving logic and health check endpoint in the new app structure
…le transport

- Added Winston as a logging library to standardize logging format.
- Introduced DailyFileTransport for log rotation and retention management.
- Enhanced app.js to log requests with unique request IDs and performance metrics.
- Updated server-local.js to handle uncaught exceptions and unhandled promise rejections.
- Modified README.md to include logging configuration details.
- Added logger.js to encapsulate logging logic and context management.
- Added `data-store.ts` for managing JSON files and serving them via json-server.
- Introduced `createDataStore` function to initialize the data store with file loading and request handling.
- Implemented caching for loaded files and created a router for handling read and write requests.

feat: extend Express types for middleware integration

- Created `express.d.ts` to define additional `res.locals` properties used by the application.

feat: add json-server type definitions

- Added `json-server.d.ts` to provide type definitions for json-server's router and middleware options.

feat: implement error handling utilities

- Introduced `errors.ts` with functions to safely extract error codes and HTTP status from thrown errors.

feat: create HTTP utility functions

- Added `http.ts` with helper functions for handling request paths and client addresses.

feat: add version utility

- Implemented `version.ts` to read and export the application version from `package.json`.

test: add comprehensive API tests

- Created `api.test.ts` to test the HTTP API against the data store, including reading, writing, and error handling.

test: set up environment for tests

- Added `env.ts` to configure the testing environment before loading application code.

test: implement server helper functions

- Created `helpers.ts` to manage server startup and request handling in tests.

test: add logger tests

- Implemented `logger.test.ts` to validate logging behavior and output format.

test: add server integration tests

- Created `server.test.ts` to test server startup, request handling, and shutdown logging.

build: add TypeScript configuration files

- Introduced `tsconfig.json` for type checking and `tsconfig.build.json` for production builds.

ci: configure Vitest for testing

- Added `vitest.config.ts` to set up testing environment and options for Vitest.
- Moved configuration from './config.ts' to './config/index.ts' for better organization.
- Updated logger imports throughout the application to reflect the new logging structure in './logging/logger.ts'.
- Introduced a new daily file transport for logging that rotates logs daily and compresses old logs.
- Enhanced the logger to follow the DoSelect logging standard, ensuring consistent log formatting.
- Updated middleware and route files to use the new logger path.
- Added tests to validate the new logging implementation and ensure compliance with the logging standard.
…A flows

- Introduced `config.test.ts` to validate configuration defaults and environment variable parsing.
- Added `data-store.test.ts` to test file serving, caching, and error handling in the data store.
- Enhanced `logger.test.ts` with tests for log levels, formatting, and context handling.
- Created `qa-flows.test.ts` to cover QA_GUIDE.md flows B-G against the real data folder.
- Implemented `utils.test.ts` for testing small helper functions related to HTTP utilities and error handling.
- Updated `README.md` to reflect new test files and their purposes.
…details on GET-only collection and its coverage.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Request handling can bypass security safeguards, and logging initialization and archive recovery have unresolved reliability issues.

4 open issues
What changed in this PR

Modernizes the sample REST API service for Node.js 24 LTS, replacing the legacy JavaScript server with TypeScript and adding security guards, structured logging, and automated checks.

Changes:

  • Updates runtime requirements, dependencies, development tooling, and data generators.
  • Serves deployed datasets from memory with direct routing, request guards, and graceful shutdown.
  • Adds API and logging tests, QA documentation, Postman coverage, and expanded sample notes.
File Description
vitest.config.ts Configures test discovery, isolation, and timeouts.
tsconfig.json Enables strict TypeScript checking and native execution compatibility.
tsconfig.build.json Configures optional JavaScript builds.
test/​utils.test.ts Tests HTTP, error, and timestamp helpers.
test/​server.test.ts Tests startup, shutdown, and server failures.
test/​qa-flows.test.ts Automates documented API acceptance flows.
test/​logger.test.ts Tests logging format, rotation, retention, and recovery.
test/​helpers.ts Supports local and remote API testing.
test/​env.ts Sets quiet test logging defaults.
test/​data-store.test.ts Tests caching, file selection, and isolated writes.
test/​config.test.ts Tests configuration defaults and validation.
test/​api.test.ts Tests routes, simulated writes, and request guards.
src/​utils/​version.ts Reads the application version for startup logs.
src/​utils/​time.ts Formats standard UTC log timestamps.
src/​utils/​http.ts Adds request-path, address, and regex helpers.
src/​utils/​errors.ts Extracts error codes and HTTP statuses.
src/​types/​json-server.d.ts Defines types for json-server integration.
src/​types/​express.d.ts Types request-local dataset metadata.
src/​services/​data-store.ts Caches datasets and isolates simulated writes.
src/​routes/​health.ts Provides root and health responses.
src/​routes/​data.ts Routes current and legacy dataset URLs directly.
src/​middlewares/​request-guards.ts Adds body-size, query, and JSONP guards.
src/​middlewares/​request-context.ts Adds request IDs and access logging.
src/​logging/​logger.ts Implements structured logging and contextual fields.
src/​logging/​daily-file-transport.ts Adds daily log rotation and retention.
src/​index.ts Handles startup validation and graceful shutdown.
src/​constants/​logging.ts Defines logging levels and rotation constants.
src/​constants/​lifecycle.ts Bounds log flushing before exit.
src/​constants/​http.ts Centralizes routes, limits, and HTTP timeouts.
src/​config/​index.ts Loads and validates environment settings.
src/​app.ts Assembles middleware, routes, and JSON error handling.
server-local.js Removes the legacy server entry point.
seed.js Removes the legacy combined-data seeder.
README.md Documents runtime, configuration, and development workflows.
QA_GUIDE.md Defines verification flows and acceptance criteria.
postman/​README.md Documents collection usage and environments.
postman/​DoSelect-Json-Server.postman_collection.json Adds API requests and response checks.
package.json Updates dependencies, scripts, and Node requirements.
generate_data/​notes.js Removes the legacy notes generator.
generate_data/​leaves.js Removes the legacy leave generator.
generate_data/​employees.js Removes the legacy employee generator.
generate_data/​countries.js Removes the legacy country generator.
express/​json.js Removes the remote-fetching legacy application.
eslint.config.js Adds type-aware linting.
dev/​write-data.ts Standardizes generated dataset output.
dev/​types.d.ts Types generator dependencies.
dev/​generate-notes.ts Generates the expanded fixed notes dataset.
dev/​generate-leaves.ts Migrates leave generation to TypeScript.
dev/​generate-employees.ts Migrates employee generation to maintained Faker APIs.
dev/​generate-countries.ts Migrates country and flag generation to TypeScript.
data/​notes.json Expands sample notes from 10 to 50.
data/​health_check.txt Removes the obsolete health-check file.
AGENTS.md Adds session-context metadata.
.nvmrc Pins the Node.js version.
.gitignore Excludes logs, environment files, and build output.
.env.sample Documents application and logging settings.

Review effort: Balanced

Comment thread src/logging/daily-file-transport.ts Resolved
Comment thread src/utils/http.ts Resolved
Comment thread src/logging/daily-file-transport.ts Resolved
Comment thread src/middlewares/request-guards.ts Resolved
- Added `parseBody` middleware to handle JSON and form bodies with size limits.
- Improved error handling for oversized request bodies, including chunked and gzip/deflate bodies.
- Updated `endpoint` function to return raw paths for unparseable URLs without throwing errors.
- Enhanced `DailyFileTransport` to manage gzip compression and recovery of log files more effectively.
- Added tests for new request handling features and logging behavior.
@GNSubrahmanyam
GNSubrahmanyam changed the base branch from master to release October 26, 2026 12:25
@deepak-doselect
deepak-doselect requested a balanced review from Copilot October 26, 2026 13:00

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved logging issues can misattribute request context, delete recent archives, or prevent retention cleanup after compression failures.

1 open issue
2 previously missed issues

In code that hasn't changed since last review

Medium severity Reject retention values that produce an invalid archive cutoff

src/​logging/​daily-file-transport.ts:381

LOG_RETENTION_DAYS=999999999999 passes both positive-integer checks, but the cutoff becomes an Invalid Date. localDay() then returns 'NaN-NaN-NaN', and every normal archive date compares less than that string, causing even yesterday's logs to be deleted. Check that the computed cutoff is valid before comparing archive names, or reject unrepresentable retention values during configuration validation.

Medium severity Capture request context before buffering Winston log entries

src/​logging/​logger.ts:165

When a slow file transport fills Winston's buffers, queued entries can be formatted later under another request's context, giving them the wrong request_id or nested context fields. Capture the context in write() before calling target.log(), merge explicit call fields over that snapshot, and stop reading the current context in the formatter. Add a backpressure test with enough entries to exceed the stream buffers.

4 resolved since last review

Review effort: Balanced

Comment on lines +258 to +262
for (const file of files) {
const archive = path.join(dir, file)
if (pattern.test(file) && !this.#rotating.has(archive)) await this.compress(archive)
}
await this.deleteOldArchives()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants