|
8 | 8 | * |
9 | 9 | * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. |
10 | 10 | */ |
11 | | -const scheme = window.location.protocol // "http:" or "https:" |
12 | | -const hostname = '{{hostname}}' // Replace dynamically if needed |
13 | | -const sentry = '{{sentry}}' // Replace dynamically if needed |
14 | 11 |
|
15 | | -window.config = { |
16 | | - API_GATEWAY_URL: `${scheme}//gateway.${hostname}/`, |
17 | | - CONFIG_API_URL: `${scheme}//config.${hostname}`, |
18 | | - LOGIN_URL: `${scheme}//login.${hostname}`, |
19 | | - AUTH_URL: `${scheme}//gateway.${hostname}/auth/`, |
20 | | - MINIO_URL: `${scheme}//minio.${hostname}/ocrvs/`, |
21 | | - MINIO_BASE_URL: `${scheme}//minio.${hostname}`, // URL without path/bucket information, used for file uploads, v2 |
22 | | - MINIO_BUCKET: 'ocrvs', |
23 | | - COUNTRY_CONFIG_URL: `${scheme}//countryconfig.${hostname}`, |
24 | | - // Country code in uppercase ALPHA-3 format |
25 | | - COUNTRY: 'FAR', |
26 | | - LANGUAGES: 'en,fr', |
27 | | - SENTRY: sentry, |
28 | | - DASHBOARDS: [ |
29 | | - { |
30 | | - id: 'registrations', |
31 | | - title: { |
32 | | - id: 'dashboard.registrationsTitle', |
33 | | - defaultMessage: 'Registrations Dashboard', |
34 | | - description: 'Menu item for registrations dashboard' |
35 | | - }, |
36 | | - url: `${scheme}//metabase.${hostname}/public/dashboard/03be04d6-bde0-4fa7-9141-21cea2a7518b#bordered=false&titled=false&refresh=300`, // Filled in below |
37 | | - }, |
38 | | - { |
39 | | - id: 'completeness', |
40 | | - title: { |
41 | | - id: 'dashboard.completenessTitle', |
42 | | - defaultMessage: 'Completeness Dashboard', |
43 | | - description: 'Menu item for completeness dashboard' |
| 12 | +/** |
| 13 | + * When running application in slow network condition (reproducible using 3G), the client-config.js might be loaded twice. |
| 14 | + * This results to issues like `Uncaught SyntaxError: "identifier scheme has already been declared at (client-config.js:1:1")`. |
| 15 | + * |
| 16 | + * On high level, refreshing the browser window requests new document page. The document page includes script tag to load client-config.js. |
| 17 | + * If the network is slow, the browser might start loading and executing client-config.js again before the previous one is torn down, causing the error. |
| 18 | + * |
| 19 | + */ |
| 20 | +;(function initClientConfig() { |
| 21 | + const scheme = window.location.protocol // "http:" or "https:" |
| 22 | + const hostname = '{{hostname}}' // Replaced dynamically |
| 23 | + const sentry = '{{sentry}}' // Replaced dynamically |
| 24 | + |
| 25 | + window.config = { |
| 26 | + API_GATEWAY_URL: `${scheme}//gateway.${hostname}/`, |
| 27 | + CONFIG_API_URL: `${scheme}//config.${hostname}`, |
| 28 | + LOGIN_URL: `${scheme}//login.${hostname}`, |
| 29 | + AUTH_URL: `${scheme}//gateway.${hostname}/auth/`, |
| 30 | + MINIO_URL: `${scheme}//minio.${hostname}/ocrvs/`, |
| 31 | + MINIO_BASE_URL: `${scheme}//minio.${hostname}`, // URL without path/bucket information, used for file uploads, v2 |
| 32 | + MINIO_BUCKET: 'ocrvs', |
| 33 | + COUNTRY_CONFIG_URL: `${scheme}//countryconfig.${hostname}`, |
| 34 | + // Country code in uppercase ALPHA-3 format |
| 35 | + COUNTRY: 'FAR', |
| 36 | + LANGUAGES: 'en,fr', |
| 37 | + SENTRY: sentry, |
| 38 | + DASHBOARDS: [ |
| 39 | + { |
| 40 | + id: 'registrations', |
| 41 | + title: { |
| 42 | + id: 'dashboard.registrationsTitle', |
| 43 | + defaultMessage: 'Registrations Dashboard', |
| 44 | + description: 'Menu item for registrations dashboard' |
| 45 | + }, |
| 46 | + url: `${scheme}//metabase.${hostname}/public/dashboard/03be04d6-bde0-4fa7-9141-21cea2a7518b#bordered=false&titled=false&refresh=300` |
44 | 47 | }, |
45 | | - url: `${scheme}//metabase.${hostname}/public/dashboard/41940907-8542-4e18-a05d-2408e7e9838a#bordered=false&titled=false&refresh=300`, |
46 | | - }, |
47 | | - { |
48 | | - id: 'registry', |
49 | | - title: { |
50 | | - id: 'dashboard.registryTitle', |
51 | | - defaultMessage: 'Registry', |
52 | | - description: 'Menu item for registry dashboard' |
| 48 | + { |
| 49 | + id: 'completeness', |
| 50 | + title: { |
| 51 | + id: 'dashboard.completenessTitle', |
| 52 | + defaultMessage: 'Completeness Dashboard', |
| 53 | + description: 'Menu item for completeness dashboard' |
| 54 | + }, |
| 55 | + url: `${scheme}//metabase.${hostname}/public/dashboard/41940907-8542-4e18-a05d-2408e7e9838a#bordered=false&titled=false&refresh=300` |
53 | 56 | }, |
54 | | - url: `${scheme}//metabase.${hostname}/public/dashboard/dc66b77a-79df-4f68-8fc8-5e5d5a2d7a35#bordered=false&titled=false&refresh=300`, |
| 57 | + { |
| 58 | + id: 'registry', |
| 59 | + title: { |
| 60 | + id: 'dashboard.registryTitle', |
| 61 | + defaultMessage: 'Registry', |
| 62 | + description: 'Menu item for registry dashboard' |
| 63 | + }, |
| 64 | + url: `${scheme}//metabase.${hostname}/public/dashboard/dc66b77a-79df-4f68-8fc8-5e5d5a2d7a35#bordered=false&titled=false&refresh=300` |
| 65 | + } |
| 66 | + ], |
| 67 | + // NOTE: This is not valid javascript until replaced during build time. |
| 68 | + // IIFE just reveals it. |
| 69 | + FEATURES: { |
| 70 | + // The V2_EVENTS variable is passed down from src/index.ts:309 |
| 71 | + V2_EVENTS: {{ V2_EVENTS }} |
55 | 72 | } |
56 | | - ], |
57 | | - FEATURES: { |
58 | | - // The V2_EVENTS variable is passed down from src/index.ts:309 |
59 | | - V2_EVENTS: {{ V2_EVENTS }} |
60 | 73 | } |
61 | | -} |
| 74 | +})() |
0 commit comments