tercul-frontend/server/middleware/graphql.ts
Damir Mukimov 4a23f496fa
Major frontend development updates
- Enhanced annotation system with improved inline editing
- Updated author components with new card and header designs
- Improved reading view with enhanced line numbering and controls
- Added new blog management features and tag management
- Updated UI components with improved accessibility and styling
- Enhanced search functionality with better filtering
- Added new dashboard features and activity feeds
- Improved translation selector and work comparison tools
- Updated GraphQL integration and API hooks
- Enhanced responsive design and mobile experience
2025-11-27 03:44:09 +01:00

30 lines
809 B
TypeScript

import type { Request, Response, NextFunction } from "express";
import { GraphQLClient } from "graphql-request";
// Attach a per-request GraphQL client with dynamic headers (e.g., auth)
interface GraphQLAugmentedRequest extends Request {
gql?: GraphQLClient;
}
export function attachGraphQLClient(
req: Request,
_res: Response,
next: NextFunction
) {
const endpoint =
process.env.GO_GRAPHQL_URL || "http://localhost:8080/graphql";
const headers: Record<string, string> = {};
// Propagate Authorization header if present
if (req.headers.authorization) {
headers["authorization"] = req.headers.authorization;
}
// TODO[P2]: Add request-scoped correlation ID / tracing headers
(req as GraphQLAugmentedRequest).gql = new GraphQLClient(endpoint, {
headers,
});
next();
}