Skip to content

Commit

Permalink
load config file syncronously #137
Browse files Browse the repository at this point in the history
  • Loading branch information
ukorvl committed Jul 18, 2023
1 parent 0f4c8c7 commit 7b85202
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
src="/tomlParser.js">
</script>
<script type="text/javascript">
async function loadConfig() {
function loadConfig() {
var configPath;

// ejs syntax
Expand All @@ -105,10 +105,19 @@
configPath = './runtime-config.dev.toml';
}

var result = await fetch(configPath);
var rawConfig = await result.text();
config = tomlParser.parse(rawConfig);
window['RUNTIME_CONFIG'] = config;
var rawFile = new XMLHttpRequest();
rawFile.open("GET", configPath, false);

rawFile.onreadystatechange = function () {
if(rawFile.readyState === 4) {
if(rawFile.status === 200 || rawFile.status == 0) {
var rawConfig = rawFile.responseText;
config = tomlParser.parse(rawConfig);
window['RUNTIME_CONFIG'] = config;
}
}
}
rawFile.send(null);
}

loadConfig();
Expand Down

0 comments on commit 7b85202

Please sign in to comment.