Repository navigation
DINO-839: support loading ui feature flags via backends app props (ja… #1075
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
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
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,70 @@ | ||
| import type { Plugin } from "vite"; | ||
|
|
||
| import { readFile } from "node:fs/promises"; | ||
| import { resolve } from "node:path"; | ||
|
|
||
| const placeholder = "__CODEBLOOM_CONFIG__"; | ||
|
|
||
| /** | ||
| * Create codebloom-config by calling the Java backend to get fully transformed index.html | ||
| * */ | ||
| export function runtimeConfigPlugin(backendUrl: string): Plugin { | ||
| async function inject(html: string): Promise<string> { | ||
| const response = await fetch(new URL("/index.html", backendUrl), { | ||
| signal: AbortSignal.timeout(5000), | ||
| }); | ||
| if (!response.ok) { | ||
| throw new Error(`Backend HTML bootstrap failed: HTTP ${response.status}`); | ||
| } | ||
|
|
||
| const backendHtml = await response.text(); | ||
| const config = backendHtml.match( | ||
| /<script\b[^>]*\bid=["']codebloom-config["'][^>]*>([\s\S]*?)<\/script>/i, | ||
| )?.[1]; | ||
| if (!config || !html.includes(placeholder)) { | ||
| throw new Error("Application HTML is missing its runtime configuration"); | ||
| } | ||
|
|
||
| JSON.parse(config); | ||
| return html.replace(placeholder, () => config); | ||
| } | ||
|
|
||
| return { | ||
| name: "codebloom-runtime-config", | ||
| apply: "serve", | ||
| transformIndexHtml: { | ||
| order: "pre", | ||
| handler: inject, | ||
| }, | ||
| configurePreviewServer(server) { | ||
| const html = readFile( | ||
| resolve(server.config.root, server.config.build.outDir, "index.html"), | ||
| "utf8", | ||
| ); | ||
| server.middlewares.use((request, response, next) => { | ||
| const pathname = new URL(request.url ?? "/", "http://localhost") | ||
| .pathname; | ||
| const isHtml = | ||
| pathname === "/" || | ||
| pathname === "/index.html" || | ||
| request.headers.accept?.includes("text/html"); | ||
| if ( | ||
| !isHtml || | ||
| pathname.startsWith("/api") || | ||
| (request.method !== "GET" && request.method !== "HEAD") | ||
| ) { | ||
| next(); | ||
| return; | ||
| } | ||
| void html | ||
| .then(inject) | ||
| .then((body) => { | ||
| response.setHeader("Content-Type", "text/html; charset=utf-8"); | ||
| response.setHeader("Cache-Control", "no-store"); | ||
| response.end(request.method === "HEAD" ? undefined : body); | ||
| }) | ||
| .catch(next); | ||
| }); | ||
| }, | ||
| }; | ||
| } | ||
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
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.