-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
62 lines (60 loc) · 1.66 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
60
61
62
const localtunnel = require('localtunnel');
module.exports = {
// define props
configSchema: {
subdomain: {
type: 'string',
description:
'A string value requesting a specific subdomain on the proxy server'
},
localhost: {
type: 'string',
description: 'Proxy to this hostname instead of localhost'
},
host: {
type: 'string',
description:
'use your own localtunnel server, defualt is "https://localtunnel.me"'
}
},
hooks: {
async onCreate({ config, events, logger }) {
let tunnel;
events.on('ready', () => {
const stopSpin = logger.spin('connecting to localtunnel...');
const port = config.get('$.port');
const { chalk } = logger;
tunnel = localtunnel(
port,
{
host: config.get('host'),
local_host: config.get('localhost'),
subdomain: config.get('subdomain')
},
(err, tunnel) => {
stopSpin();
if (err) {
logger.error(
`localtunnel setup failed, beacuse {err.stack || err.message}`
);
events.emit('localtunnel:error', err.message);
}
logger.notify(
`url is available at ${chalk.underline.blue(tunnel.url)}`
);
events.emit('localtunnel:ready', tunnel);
}
);
tunnel.on('error', err => {
stopSpin();
logger.error(err.message);
events.emit('localtunnel:error', err.message);
});
});
// onCreate
return () => {
if (tunnel) tunnel.close();
};
}
}
};