Repository navigation
fix(@redhat-cloud-services/frontend-components-config-utilities): reload nav on CRD change #2391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
karelhala
merged 4 commits into
RedHatInsights:master
from
platex-rehor-bot:bot/RHCLOUD-49555
Jul 24, 2026
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4aad0a3
fix(@redhat-cloud-services/frontend-components-config-utilities): rel…
platex-rehor-bot 1e8e37d
fix(@redhat-cloud-services/frontend-components-config-utilities): pre…
platex-rehor-bot 2dca5ad
feat(@redhat-cloud-services/frontend-components-config): add CRD inte…
platex-rehor-bot 282c2cd
fix(@redhat-cloud-services/frontend-components-config): harden CRD in…
platex-rehor-bot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,192 @@ | ||
| import http from 'http'; | ||
| import https from 'https'; | ||
| import { URL } from 'url'; | ||
| import chokidar from 'chokidar'; | ||
| import { HttpsProxyAgent } from 'https-proxy-agent'; | ||
| import { readFrontendCRD } from '@redhat-cloud-services/frontend-components-config-utilities/feo/crd-check'; | ||
| import { FrontendCRD } from '@redhat-cloud-services/frontend-components-config-utilities/feo/feo-types'; | ||
| import { modifyRequest } from '@redhat-cloud-services/frontend-components-config-utilities/feo/modify-response'; | ||
| import { LogType, fecLogger } from '@redhat-cloud-services/frontend-components-config-utilities'; | ||
|
|
||
| const PROXY_URL = 'http://squid.corp.redhat.com:3128'; | ||
|
|
||
| export const CRD_INTERCEPTOR_PORT = 9997; | ||
|
|
||
| /** | ||
| * The 4 chrome-service API endpoints that need CRD interception. | ||
| * These are the same URLs matched by isInterceptAbleRequest() in config-utils. | ||
| */ | ||
| export const INTERCEPTABLE_PATHS = [ | ||
| '/api/chrome-service/v1/static/bundles-generated.json', | ||
| '/api/chrome-service/v1/static/search-index-generated.json', | ||
| '/api/chrome-service/v1/static/service-tiles-generated.json', | ||
| '/api/chrome-service/v1/static/fed-modules-generated.json', | ||
| ]; | ||
|
|
||
| interface CRDInterceptorOptions { | ||
| frontendCRDPath: string; | ||
| port?: number; | ||
| debug?: boolean; | ||
| } | ||
|
|
||
| /** | ||
| * Starts a Node HTTP server that intercepts chrome-service API responses | ||
| * and applies local CRD modifications via modifyRequest(). | ||
| * | ||
| * This brings CRD interception support to `fec dev-proxy` mode, where the | ||
| * Caddy container normally proxies /api/* directly to stage without any | ||
| * local CRD awareness. The Caddy routes config directs the 4 interceptable | ||
| * API paths to this server instead, which fetches from upstream, applies | ||
| * CRD modifications, and returns the modified response. | ||
| * | ||
| * Reuses 100% of the existing interception code from config-utils: | ||
| * navigationInterceptor, searchInterceptor, moduleInterceptor, | ||
| * serviceTilesInterceptor (via modifyRequest). | ||
| */ | ||
| export async function startCRDInterceptorServer(options: CRDInterceptorOptions): Promise<http.Server> { | ||
| const { frontendCRDPath, port = CRD_INTERCEPTOR_PORT, debug = false } = options; | ||
|
|
||
| const log = (logType: LogType, ...data: any[]) => { | ||
| if (logType === LogType.debug && !debug) return; | ||
| fecLogger(logType, ...data); | ||
| }; | ||
|
|
||
| // Read and watch the CRD file, same pattern as proxy.ts | ||
| const frontendCrdRef: { current?: FrontendCRD } = { current: undefined }; | ||
| try { | ||
| frontendCrdRef.current = readFrontendCRD(frontendCRDPath); | ||
| } catch (e) { | ||
| log(LogType.warn, `CRD interceptor: Unable to read frontend CRD at ${frontendCRDPath}`); | ||
| } | ||
|
|
||
| const watcher = chokidar.watch(frontendCRDPath).on('change', () => { | ||
| log(LogType.info, 'CRD interceptor: Frontend CRD changed, reloading'); | ||
| try { | ||
| frontendCrdRef.current = readFrontendCRD(frontendCRDPath); | ||
| } catch (error) { | ||
| log(LogType.error, 'CRD interceptor: Error reloading CRD', error); | ||
| } | ||
| }); | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| const hccEnvUrl = process.env.HCC_ENV_URL!; | ||
| const isStage = process.env.HCC_ENV === 'stage'; | ||
| const agent = isStage ? new HttpsProxyAgent(PROXY_URL) : undefined; | ||
|
|
||
| const server = http.createServer((req, res) => { | ||
| const url = req.url || '/'; | ||
|
|
||
| if (!frontendCrdRef.current) { | ||
| log(LogType.warn, `CRD interceptor: No CRD loaded, proxying ${url} without modification`); | ||
| proxyPassthrough(url, req, res, hccEnvUrl, agent, log); | ||
| return; | ||
| } | ||
|
|
||
| // Proxy to upstream (always HTTPS for HCC environments) and apply | ||
| // CRD modifications to the response | ||
| const upstreamUrl = new URL(url, hccEnvUrl); | ||
|
|
||
| const headers: Record<string, string | string[] | undefined> = { | ||
| ...req.headers, | ||
| host: upstreamUrl.hostname, | ||
| }; | ||
| // Prevent 304 responses that would bypass content modification | ||
| delete headers['if-none-match']; | ||
| delete headers['if-modified-since']; | ||
|
|
||
| const proxyReq = https.request( | ||
| { | ||
| hostname: upstreamUrl.hostname, | ||
| port: upstreamUrl.port || 443, | ||
| path: upstreamUrl.pathname + upstreamUrl.search, | ||
| method: req.method, | ||
| headers, | ||
| // HttpsProxyAgent v5 extends agent-base Agent, not https.Agent, | ||
| // but is fully compatible at runtime | ||
| agent: agent as https.Agent | undefined, | ||
| }, | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| (proxyRes) => { | ||
| let body = ''; | ||
| proxyRes.on('data', (chunk: Buffer) => { | ||
| body += chunk.toString(); | ||
| }); | ||
| proxyRes.on('end', () => { | ||
| try { | ||
| const modified = modifyRequest(body, url, frontendCrdRef.current!); | ||
| res.writeHead(200, { | ||
| 'content-type': 'application/json', | ||
| 'content-length': Buffer.byteLength(modified), | ||
| 'cache-control': 'no-store, no-cache, must-revalidate', | ||
| }); | ||
| res.end(modified); | ||
| log(LogType.debug, `CRD interceptor: Modified response for ${url}`); | ||
| } catch (error) { | ||
| log(LogType.error, `CRD interceptor: Error modifying response for ${url}`, error); | ||
| res.writeHead(proxyRes.statusCode || 500, { | ||
| 'content-type': proxyRes.headers['content-type'] || 'application/json', | ||
| }); | ||
| res.end(body); | ||
| } | ||
| }); | ||
| }, | ||
| ); | ||
|
|
||
| proxyReq.on('error', (error) => { | ||
| log(LogType.error, `CRD interceptor: Upstream request failed for ${url}`, error); | ||
| res.writeHead(502, { 'content-type': 'application/json' }); | ||
| res.end(JSON.stringify({ error: 'Upstream request failed' })); | ||
| }); | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| req.pipe(proxyReq); | ||
| }); | ||
|
|
||
| const cleanup = () => { | ||
| watcher.close(); | ||
| }; | ||
|
|
||
| process.on('SIGTERM', cleanup); | ||
| process.on('SIGINT', cleanup); | ||
|
|
||
| return new Promise((resolve, reject) => { | ||
| server.listen(port, () => { | ||
| log(LogType.info, `CRD interceptor server listening on port ${port}`); | ||
| resolve(server); | ||
| }); | ||
| server.on('error', reject); | ||
| }); | ||
| } | ||
|
|
||
| function proxyPassthrough( | ||
| url: string, | ||
| req: http.IncomingMessage, | ||
| res: http.ServerResponse, | ||
| hccEnvUrl: string, | ||
| agent: HttpsProxyAgent | undefined, | ||
| log: (logType: LogType, ...data: any[]) => void, | ||
| ) { | ||
| const upstreamUrl = new URL(url, hccEnvUrl); | ||
|
|
||
| const proxyReq = https.request( | ||
| { | ||
| hostname: upstreamUrl.hostname, | ||
| port: upstreamUrl.port || 443, | ||
| path: upstreamUrl.pathname + upstreamUrl.search, | ||
| method: req.method, | ||
| headers: { ...req.headers, host: upstreamUrl.hostname }, | ||
| agent: agent as https.Agent | undefined, | ||
| }, | ||
| (proxyRes) => { | ||
| res.writeHead(proxyRes.statusCode || 200, proxyRes.headers); | ||
| proxyRes.pipe(res); | ||
| }, | ||
| ); | ||
|
|
||
| proxyReq.on('error', (error) => { | ||
| log(LogType.error, `CRD interceptor: Passthrough request failed for ${url}`, error); | ||
| res.writeHead(502); | ||
| res.end('Upstream error'); | ||
| }); | ||
|
|
||
| req.pipe(proxyReq); | ||
| } | ||
|
|
||
| export default startCRDInterceptorServer; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟠 Major | 🏗️ Heavy lift
Add unit tests for the new
onProxyReqheader-stripping andtriggerReloadreload signaling.Neither the conditional-request header removal (Lines 247-254) nor the
triggerReload→server.sendMessage(..., 'content-changed')wiring (Lines 357-365) appear to have accompanying tests. As per coding guidelines, "All functions in@redhat-cloud-services/frontend-components-config-utilitiesmust have comprehensive unit tests."Also applies to: 357-365
🤖 Prompt for AI Agents
Source: Coding guidelines