mirror of
https://github.com/hibiken/asynqmon.git
synced 2025-10-26 08:16:10 +08:00
Add concept of Flag values under window object to ensure values are
parsed before use
This commit is contained in:
42
ui/src/parseFlags.ts
Normal file
42
ui/src/parseFlags.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
// Prefix used for go template
|
||||
const goTmplActionPrefix = "/[[";
|
||||
|
||||
// paseses flags (string values) assigned under the window objects by server.
|
||||
export default function parseFlagsUnderWindow() {
|
||||
// ROOT_PATH
|
||||
if (window.FLAG_ROOT_PATH === undefined) {
|
||||
console.log("ROOT_PATH is not defined. Falling back to emtpy string");
|
||||
window.ROOT_PATH = "";
|
||||
} else {
|
||||
window.ROOT_PATH = window.FLAG_ROOT_PATH;
|
||||
}
|
||||
|
||||
// PROMETHEUS_SERVER_ADDRESS
|
||||
if (window.FLAG_PROMETHEUS_SERVER_ADDRESS === undefined) {
|
||||
console.log(
|
||||
"PROMETHEUS_SERVER_ADDRESS is not defined. Falling back to emtpy string"
|
||||
);
|
||||
window.PROMETHEUS_SERVER_ADDRESS = "";
|
||||
} else if (
|
||||
window.FLAG_PROMETHEUS_SERVER_ADDRESS.startsWith(goTmplActionPrefix)
|
||||
) {
|
||||
console.log(
|
||||
"PROMETHEUS_SERVER_ADDRESS was not evaluated by the server. Falling back to empty string"
|
||||
);
|
||||
window.PROMETHEUS_SERVER_ADDRESS = "";
|
||||
} else {
|
||||
}
|
||||
|
||||
// READ_ONLY
|
||||
if (window.FLAG_READ_ONLY === undefined) {
|
||||
console.log("READ_ONLY is not defined. Falling back to false");
|
||||
window.READ_ONLY = false;
|
||||
} else if (window.FLAG_READ_ONLY.startsWith(goTmplActionPrefix)) {
|
||||
console.log(
|
||||
"READ_ONLY was not evaluated by the server. Falling back to false"
|
||||
);
|
||||
window.READ_ONLY = false;
|
||||
} else {
|
||||
window.READ_ONLY = window.FLAG_READ_ONLY === "true";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user