Skip to content

Fix broken src/index.ts: remove duplicate metric imports, add missing imports, and wire body-size guards #182

Description

@greatest0fallt1me

Description

The application entrypoint src/index.ts does not compile cleanly: { metricsHandler, metricsMiddleware } is imported four times (lines 9, 12, 14, 17), and the file references NextFunction, ErrorRequestHandler, WebhookDeliveryService, and webhookRepository without importing any of them. In addition, the rejectOversizedJsonPayload and httpBodyErrorHandler guards are defined in the file but never registered on the Express app, and metricsMiddleware/metricsHandler are imported but never used. This issue makes src/index.ts a clean, buildable bootstrap.

Requirements and context

  • Collapse the four duplicate ./metrics/prometheus imports into a single import.
  • Add the missing type imports NextFunction and ErrorRequestHandler from express.
  • Import WebhookDeliveryService from ./services/webhookDeliveryService and webhookRepository from ./repositories/webhookRepository (both already exported in the repo).
  • Register metricsMiddleware early in the middleware chain and expose metricsHandler at GET /metrics.
  • Wire rejectOversizedJsonPayload before express.json() and register httpBodyErrorHandler as an error handler after the routes so the existing 413/400 responses actually fire.
  • Non-functional: npm run build must succeed with no TypeScript errors; no behavior change to the existing /health, /api/openapi.json, and /api/v1/streams routes.

Acceptance criteria

  • ./metrics/prometheus is imported exactly once and both exports are referenced.
  • NextFunction, ErrorRequestHandler, WebhookDeliveryService, and webhookRepository are imported and resolve.
  • metricsMiddleware is applied and GET /metrics returns Prometheus text via metricsHandler.
  • rejectOversizedJsonPayload and httpBodyErrorHandler are registered and an oversized JSON body returns HTTP 413.
  • npm run build exits 0 with no duplicate-import or unresolved-symbol errors.
  • Existing endpoints continue to behave as before.

Suggested execution

1. Fork the repo and create a branchgit checkout -b feature/fix-index-bootstrap.
2. Implement changes — edit src/index.ts: dedupe imports, add the missing imports, register the metrics middleware/route and the body-size guard + error handler.
3. Write/extend tests — this repo uses Jest + Supertest. Add src/__tests__/index.bootstrap.test.ts that imports app and uses Supertest to assert GET /metrics is 200 and that an oversized JSON POST returns 413, alongside the existing src/httpLimits.test.ts patterns.
4. Test and commit

npm run lint -- --max-warnings 0
npm run build
npm test

Example commit message

fix(server): dedupe metric imports and wire body-size guards in index.ts

Guidelines

Keep coverage for any new module at the repo standard (95% per jest.config.js). Update README.md if you add the GET /metrics route to the documented surface. Do not change unrelated middleware ordering. Timeframe: 96 hours.

Metadata

Metadata

Assignees

No one assigned

    Labels

    GRANTFOX OSSGrantFox OSS programMAYBE REWARDEDGrantFox — potentially rewardedOFFICIAL CAMPAIGNGrantFox official campaignbackendBackend servicedxDeveloper experienceimprovementRefactor, performance, or tech-debtintermediateModerate complexity

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions