1 | import localtunnel from '@chromaui/localtunnel';
|
2 | import setupDebug from 'debug';
|
3 |
|
4 | import { CHROMATIC_TUNNEL_URL } from '../constants';
|
5 |
|
6 | const debug = setupDebug('chromatic-cli:tunnel');
|
7 |
|
8 | export default async function openTunnel({ port, https, host = 'localhost', ...rest }) {
|
9 | if (!port) {
|
10 | throw new Error('Need to pass a port into `openTunnel`');
|
11 | }
|
12 |
|
13 | const tunnel = await localtunnel({
|
14 |
|
15 | host: CHROMATIC_TUNNEL_URL,
|
16 | port,
|
17 |
|
18 |
|
19 | local_host: host,
|
20 | ...rest,
|
21 |
|
22 |
|
23 | https: !!https,
|
24 | cert: https && https.cert,
|
25 | key: https && https.key,
|
26 | ca: https && https.ca,
|
27 | });
|
28 |
|
29 | tunnel.on('url', url => debug(`Got tunnel url: %s`, url));
|
30 | tunnel.on('request', request => debug(`Got request: %O`, request));
|
31 | tunnel.tunnelCluster.on('error', error => debug(`Got tunnel cluster error: %O`, error));
|
32 |
|
33 | return tunnel;
|
34 | }
|