-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
83 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
# 0.0.15 | ||
|
||
* DDB Config fetch | ||
|
||
# 0.0.14 | ||
|
||
* `/ping` endpoint | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
const fetch = require("node-fetch"); | ||
const CONFIG = require("./config.js"); | ||
const Cache = require("./cache.js"); | ||
|
||
var CACHE_CONFIG = new Cache("CONFIG", 1); | ||
|
||
const getConfig= () => { | ||
return new Promise((resolve, reject) => { | ||
console.log("Retrieving ddb config"); | ||
|
||
const cache = CACHE_CONFIG.exists("DDB_CONFIG"); | ||
console.warn(cache); | ||
if (cache !== undefined) { | ||
console.log("CONFIG API CACHE_CONFIG HIT!"); | ||
return resolve(cache.data); | ||
} | ||
|
||
const url = CONFIG.urls.configUrl; | ||
const options = { | ||
credentials: "include", | ||
headers: { | ||
"User-Agent": "Foundry VTT Character Integrator", | ||
"Accept": "*/*", | ||
}, | ||
method: "GET", | ||
mode: "cors", | ||
redirect: "follow", | ||
}; | ||
|
||
fetch(url, options) | ||
.then(res => res.json()) | ||
.then(json => { | ||
if (json && json.sources) { | ||
CACHE_CONFIG.add("DDB_CONFIG", json); | ||
console.log( | ||
"Adding CACHE_CONFIG to cache..." | ||
); | ||
resolve(json); | ||
} else { | ||
console.log("Received no valid config data, instead:" + json); | ||
reject(json); | ||
} | ||
}) | ||
.catch(error => { | ||
console.log("Error retrieving DDB Config"); | ||
console.log(error); | ||
reject(error); | ||
}); | ||
|
||
}); | ||
}; | ||
|
||
exports.getConfig = getConfig; |