1 | let initialized = false;
|
2 | const queue = [];
|
3 | console.log("importing rediretor");
|
4 | const Redirector = require("./lib/redirects.js");
|
5 | console.log("redirector imported");
|
6 | Redirector.onRuntimeInitialized = () => {
|
7 | console.log("Initialized!");
|
8 | initialized = true;
|
9 | queue.forEach(cb => cb.call());
|
10 | };
|
11 |
|
12 | function newParser(options) {
|
13 | if (initialized) {
|
14 | return Promise.resolve(new Redirector.RedirectParser(options));
|
15 | }
|
16 | return new Promise((resolve, reject) => {
|
17 | queue.push(() => resolve(new Redirector.RedirectParser(options)));
|
18 | });
|
19 | }
|
20 |
|
21 | module.exports = {
|
22 | parsePlain(rules, options) {
|
23 | return newParser(options).then(p => p.parsePlain(rules));
|
24 | },
|
25 | parseJSON(rules, options) {
|
26 | return newParser(options).then(p => p.parseJSON(rules));
|
27 | }
|
28 | };
|