|
24 | 24 | export function getRootPath() { |
25 | 25 | const scriptElement = document.querySelector('script[src*="bundle"]'); |
26 | 26 |
|
27 | | - if (scriptElement && scriptElement.getAttribute('src')) { |
| 27 | + if (scriptElement?.getAttribute('src')) { |
28 | 28 | const scriptPath = new URL(scriptElement.getAttribute('src')!, window.location.href).pathname; |
29 | 29 | // Positive lookahead to match everything up to bundle.js |
30 | | - const match = scriptPath.match(/(.*?)(?=bundle)/); |
31 | | - return match ? (match[1].endsWith('/') ? match[1].slice(0, -1) : match[1]) : ''; |
| 30 | + const regex = /(.*?)(?=bundle)/; |
| 31 | + const match = regex.exec(scriptPath); |
| 32 | + let rootPath = ''; |
| 33 | + if (match) { |
| 34 | + rootPath = match[1].endsWith('/') ? match[1].slice(0, -1) : match[1]; |
| 35 | + } |
| 36 | + return rootPath; |
32 | 37 | } |
33 | 38 | return ''; |
34 | 39 | } |
35 | 40 |
|
36 | | -/** |
37 | | - * Setup console logging to add a prefix to all console logs |
38 | | - * Enabling proper distinction between logs from the service and other sources |
39 | | - */ |
40 | | -export function setupConsoleLogging() { |
41 | | - const originalConsoleLog = console.log; |
42 | | - console.log = (...args) => { |
43 | | - originalConsoleLog('[ml-forecast]', ...args); |
44 | | - }; |
45 | | - |
46 | | - const originalConsoleInfo = console.info; |
47 | | - console.info = (...args) => { |
48 | | - originalConsoleInfo('[ml-forecast]', ...args); |
49 | | - }; |
50 | | - |
51 | | - const originalConsoleWarn = console.warn; |
52 | | - console.warn = (...args) => { |
53 | | - originalConsoleWarn('[ml-forecast]', ...args); |
54 | | - }; |
55 | | - |
56 | | - const originalConsoleError = console.error; |
57 | | - console.error = (...args) => { |
58 | | - originalConsoleError('[ml-forecast]', ...args); |
59 | | - }; |
60 | | -} |
61 | | - |
62 | 41 | /** |
63 | 42 | * Get the realm search param from the url (?realm=) |
64 | 43 | * @returns The realm search param |
|
0 commit comments