-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
59 lines (48 loc) · 1.27 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { Lokal } from 'lokal-js';
class lokalTunnel {
constructor(options = {}) {
this.options = options;
this.hasRun = false;
this.isDev = !!options.isDev || process.env.NODE_ENV !== 'production';
}
apply(compiler) {
compiler.hooks.afterEmit.tapAsync('LokalTunnelPlugin', async (compilation, callback) => {
if (this.hasRun || !this.isDev) {
callback();
return;
}
try {
const { tunnelName, lanAddress, publicAddress, debugMode, baseURL } = this.options;
const port = parseInt(process.env.PORT);
const host = 'localhost';
if (port > 0) {
let lokal = new Lokal();
if (debugMode) {
lokal = lokal.debugMode(true);
}
if (baseURL) {
lokal.setBaseURL(baseURL);
}
await lokal
.newTunnel()
.setLocalAddress(`${host}:${port}`)
.setTunnelType('HTTP')
.setName(tunnelName)
.setPublicAddress(publicAddress)
.setLANAddress(lanAddress)
.showStartupBanner()
.ignoreDuplicate()
.create();
console.log('Lokal tunnel created successfully');
} else {
console.warn('Cannot run Lokal:', host, port);
}
this.hasRun = true;
} catch (error) {
console.error('Error in lokalTunnel:', error);
}
callback();
});
}
}
export default lokalTunnel;