-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
30 lines (28 loc) · 1.09 KB
/
index.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
module.exports = function(remotePath,name) {
return `promise new Promise(res => {
let remote
const remotePath = "${remotePath}"
try {
remote = require(remotePath)['${name}']
} catch (e) {
delete require.cache[remotePath]
remote = require(remotePath)['${name}']
}
if(!remote || !remote.get) {
return new Promise(function(delayResolve){
var interval = setInterval(function(){
delete require.cache[remotePath]
remote = require(remotePath);
if(require(remotePath)) {
delayResolve(require(remotePath)['${name}']);
clearInterval(interval);
}
}, 100)
}).then(function(){
setTimeout(function(){res(remote)},0)
})
}
const proxy = {get:(request)=> remote.get(request),init:(arg)=>{try {return remote.init(arg)} catch(e){console.log('remote container already initialized')}}}
res(proxy)
})`
}