forked from MrPrimate/ddb-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lookup.js
53 lines (46 loc) · 1.29 KB
/
lookup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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;