feat: dynamic backend

This commit is contained in:
2022-08-12 23:22:15 +08:00
parent bedf939f4d
commit 7df8b39061
5 changed files with 51 additions and 25 deletions

View File

@@ -14,10 +14,16 @@ import renderMd from './Markdown';
export { format_time, Time, TitleLine };
export const API_BASE = `${process.env.REACT_APP_BACKEND || '/'}_api/v1`;
export const API_BASE_2 = `${process.env.REACT_APP_BACKEND || '/'}_api/v2`;
export const STORAGE_BASE = `${process.env.REACT_APP_STORAGE || '/'}`;
export function get_api_base() {
return `${window.BACKEND}_api/v1`;
}
export function get_api_base_2() {
return `${window.BACKEND}_api/v2`;
}
// https://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex
function escape_regex(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string