mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-28 00:17:12 +01:00
ui flags replaced in index.html (#2617)
Signed-off-by: andreas-unleash <andreas@getunleash.ai> <!-- Thanks for creating a PR! To make it easier for reviewers and everyone else to understand what your changes relate to, please add some relevant content to the headings below. Feel free to ignore or delete sections that you don't think are relevant. Thank you! ❤️ --> This PR puts the ui flags in the index.html in a meta tag. This makes them accessible without logging in and allows us to track user signups with invite links ## About the changes <!-- Describe the changes introduced. What are they and why are they being introduced? Feel free to also add screenshots or steps to view the changes if they're visual. --> <!-- Does it close an issue? Multiple? --> Closes # <!-- (For internal contributors): Does it relate to an issue on public roadmap? --> <!-- Relates to [roadmap](https://github.com/orgs/Unleash/projects/10) item: # --> ### Important files <!-- PRs can contain a lot of changes, but not all changes are equally important. Where should a reviewer start looking to get an overview of the changes? Are any files particularly important? --> ## Discussion points <!-- Anything about the PR you'd like to discuss before it gets merged? Got any questions or doubts? --> Signed-off-by: andreas-unleash <andreas@getunleash.ai>
This commit is contained in:
parent
8fed007fe1
commit
d69ca0a508
@ -6,6 +6,7 @@
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="baseUriPath" content="::baseUriPath::" />
|
||||
<meta name="cdnPrefix" content="::cdnPrefix::" />
|
||||
<meta name="uiFlags" content="::uiFlags::" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="description" content="unleash" />
|
||||
<title>Unleash</title>
|
||||
|
@ -11,8 +11,25 @@ export const PlausibleProvider: FC = ({ children }) => {
|
||||
const [context, setContext] = useState<ReturnType<typeof Plausible> | null>(
|
||||
null
|
||||
);
|
||||
|
||||
const getUIFlags = () => {
|
||||
try {
|
||||
const uiFlagsStr =
|
||||
(
|
||||
document.querySelector(
|
||||
'meta[name="uiFlags"]'
|
||||
) as HTMLMetaElement
|
||||
)?.content || '{}';
|
||||
return JSON.parse(uiFlagsStr);
|
||||
} catch (e) {
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
const uiFlags = getUIFlags();
|
||||
|
||||
const { uiConfig } = useUiConfig();
|
||||
const isEnabled = Boolean(uiConfig?.flags?.T || LOCAL_TESTING);
|
||||
const isEnabled = Boolean(uiConfig?.flags?.T || uiFlags.T || LOCAL_TESTING);
|
||||
|
||||
useEffect(() => {
|
||||
if (isEnabled) {
|
||||
|
@ -9,6 +9,7 @@ export async function loadIndexHTML(
|
||||
publicFolder: string,
|
||||
): Promise<string> {
|
||||
const { cdnPrefix, baseUriPath = '' } = config.server;
|
||||
const uiFlags = JSON.stringify(config.ui.flags);
|
||||
|
||||
let indexHTML: string;
|
||||
if (cdnPrefix) {
|
||||
@ -20,5 +21,5 @@ export async function loadIndexHTML(
|
||||
.toString();
|
||||
}
|
||||
|
||||
return rewriteHTML(indexHTML, baseUriPath, cdnPrefix);
|
||||
return rewriteHTML(indexHTML, baseUriPath, cdnPrefix, uiFlags);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ export const rewriteHTML = (
|
||||
input: string,
|
||||
rewriteValue: string,
|
||||
cdnPrefix?: string,
|
||||
uiFlags?: string,
|
||||
): string => {
|
||||
let result = input;
|
||||
result = result.replace(/::baseUriPath::/gi, rewriteValue);
|
||||
@ -10,6 +11,8 @@ export const rewriteHTML = (
|
||||
const faviconPrefix = cdnPrefix ? 'https://cdn.getunleash.io' : '';
|
||||
result = result.replace(/::faviconPrefix::/gi, faviconPrefix);
|
||||
|
||||
result = result.replace(/::uiFlags::/gi, uiFlags);
|
||||
|
||||
result = result.replace(
|
||||
/\/static/gi,
|
||||
`${cdnPrefix || rewriteValue}/static`,
|
||||
|
Loading…
Reference in New Issue
Block a user