Skip to content

Add request ID middleware to generated project templates #10

@PAMulligan

Description

@PAMulligan

Description

Add a request ID middleware to the initial project template generated by setup-project.sh. Every incoming request should get a unique ID that flows through logging, error responses, and response headers.

Why

Request tracing is fundamental for debugging production issues. Including it from day one means every generated API has observability built in. Hono's requestId() middleware makes this trivial.

Acceptance Criteria

  • Import and apply Hono's built-in requestId middleware in the generated src/index.ts
  • Add the request ID to the /health response (e.g., requestId field)
  • Ensure the X-Request-Id header is included in all responses
  • Apply to both Cloudflare Workers and Node.js templates
  • Update the existing health test to account for the new field
  • CI passes

Implementation

import { requestId } from 'hono/request-id';

app.use('*', requestId());

app.get('/health', (c) => {
  return c.json({
    status: 'ok',
    requestId: c.get('requestId'),
    timestamp: new Date().toISOString(),
  });
});

Metadata

Metadata

Assignees

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions