Skip to content

Commit 873d79b

Browse files
committed
added seperate profiles file
1 parent 9943955 commit 873d79b

File tree

2 files changed

+86
-79
lines changed

2 files changed

+86
-79
lines changed

src/js/configurations/profiles.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import {Config as SAConfig} from './geography_sa';
2+
import {getAPIUrl} from '../utils';
3+
4+
let config = new SAConfig();
5+
6+
const defaultHostname = 'wazimap-ng.africa';
7+
const mainUrl = getAPIUrl('https://staging.wazimap-ng.openup.org.za');
8+
const productionUrl = getAPIUrl('https://production.wazimap-ng.openup.org.za');
9+
10+
const profiles = {
11+
'wazi.webflow.io': {
12+
baseUrl: mainUrl,
13+
config: config
14+
},
15+
'localhost': {
16+
baseUrl: mainUrl,
17+
config: config
18+
},
19+
'localhost-dev': {
20+
baseUrl: 'http://localhost:8000',
21+
config: config
22+
},
23+
'geo.vulekamali.gov.za': {
24+
baseUrl: productionUrl,
25+
config: config
26+
},
27+
'beta.youthexplorer.org.za': {
28+
baseUrl: productionUrl,
29+
config: config
30+
},
31+
'capetownagainstcovid19.openup.org.za': {
32+
baseUrl: mainUrl,
33+
config: config
34+
},
35+
'covid-wazi.openup.org.za': {
36+
baseUrl: productionUrl,
37+
config: config
38+
},
39+
'wazimap-ng.africa': {
40+
baseUrl: mainUrl,
41+
config: config
42+
},
43+
'covid-ibp.openup.org.za': {
44+
baseUrl: productionUrl,
45+
config: config
46+
},
47+
'sifar-wazi.openup.org.za': {
48+
baseUrl: productionUrl,
49+
config: config
50+
},
51+
'mapyourcity.org.za': {
52+
baseUrl: productionUrl,
53+
config: config
54+
},
55+
'giz-projects.openup.org.za': {
56+
baseUrl: productionUrl,
57+
config: config
58+
},
59+
'covid-ccij.openup.org.za': {
60+
baseUrl: mainUrl,
61+
config: config
62+
},
63+
'cfafrica.wazimap-ng.africa': {
64+
baseUrl: 'https://api.cfafrica.wazimap-ng.africa',
65+
config: config
66+
},
67+
'ccij-water.openup.org.za': {
68+
baseUrl: productionUrl,
69+
config: config
70+
}
71+
}
72+
73+
export function getProfile(hostname) {
74+
let this_profile
75+
if (hostname in profiles) {
76+
this_profile = profiles[hostname]
77+
this_profile.hostname = hostname
78+
} else {
79+
this_profile = profiles[defaultHostname]
80+
this_profile.hostname = defaultHostname
81+
}
82+
return this_profile
83+
}

src/js/index.js

Lines changed: 3 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,9 @@ import {API} from './api';
77
import * as Sentry from '@sentry/browser';
88
import {getHostname, getAPIUrl, loadDevTools} from './utils';
99
import {ErrorNotifier} from "./error-notifier";
10-
11-
const mainUrl = getAPIUrl('https://staging.wazimap-ng.openup.org.za');
12-
const productionUrl = getAPIUrl('https://production.wazimap-ng.openup.org.za');
13-
let config = new SAConfig();
10+
import {getProfile} from './configurations/profiles'
1411

1512
let hostname = getHostname();
16-
const defaultProfile = 8;
17-
const defaultUrl = productionUrl;
18-
const defaultConfig = new SAConfig();
1913

2014
const ENVIRONMENT = `${process.env.ENVIRONMENT}`;
2115
const GOOGLE_ANALYTICS_ID = `${process.env.GOOGLE_ANALYTICS_ID}`;
@@ -30,84 +24,14 @@ if (SENTRY_DSN !== "undefined" && SENTRY_DSN !== "") {
3024
console.warn("Not initialising Sentry because SENTRY_DSN is not set");
3125
}
3226

33-
const profiles = {
34-
'wazi.webflow.io': {
35-
baseUrl: mainUrl,
36-
config: config
37-
},
38-
'localhost': {
39-
baseUrl: mainUrl,
40-
config: config
41-
},
42-
'localhost-dev': {
43-
baseUrl: 'http://localhost:8000',
44-
config: config
45-
},
46-
'geo.vulekamali.gov.za': {
47-
baseUrl: productionUrl,
48-
config: config
49-
},
50-
'beta.youthexplorer.org.za': {
51-
baseUrl: productionUrl,
52-
config: config
53-
},
54-
'capetownagainstcovid19.openup.org.za': {
55-
baseUrl: mainUrl,
56-
config: config
57-
},
58-
'covid-wazi.openup.org.za': {
59-
baseUrl: productionUrl,
60-
config: config
61-
},
62-
'wazimap-ng.africa': {
63-
baseUrl: mainUrl,
64-
config: config
65-
},
66-
'covid-ibp.openup.org.za': {
67-
baseUrl: productionUrl,
68-
config: config
69-
},
70-
'sifar-wazi.openup.org.za': {
71-
baseUrl: productionUrl,
72-
config: config
73-
},
74-
'mapyourcity.org.za': {
75-
baseUrl: productionUrl,
76-
config: config
77-
},
78-
'giz-projects.openup.org.za': {
79-
baseUrl: productionUrl,
80-
config: config
81-
},
82-
'covid-ccij.openup.org.za': {
83-
baseUrl: mainUrl,
84-
config: config
85-
},
86-
'cfafrica.wazimap-ng.africa': {
87-
baseUrl: 'https://api.cfafrica.wazimap-ng.africa',
88-
config: config
89-
},
90-
'ccij-water.openup.org.za': {
91-
baseUrl: productionUrl,
92-
config: config
93-
}
94-
}
95-
9627
async function init() {
97-
let pc = profiles[hostname]
98-
if (pc == undefined) {
99-
pc = {
100-
profile: defaultProfile,
101-
baseUrl: defaultUrl,
102-
config: defaultConfig
103-
}
104-
}
28+
let pc = getProfile(hostname)
10529

10630
const errorNotifier = new ErrorNotifier();
10731
errorNotifier.registerErrorHandler();
10832

10933
const api = new API(pc.baseUrl, pc.config);
110-
const data = await api.getProfileConfiguration(hostname);
34+
const data = await api.getProfileConfiguration(pc.hostname);
11135

11236
pc.config.setConfig(data.configuration || {})
11337
pc.config.setVersions(data.geography_hierarchy || {})

0 commit comments

Comments
 (0)