(apiUrl: string, apiKey: string, endpoint: ServerEndpoint)
| 477 | } |
| 478 | |
| 479 | async function resolveEndpointUrl(apiUrl: string, apiKey: string, endpoint: ServerEndpoint) { |
| 480 | // use tunnel URL if provided |
| 481 | if (endpoint.type === "tunnel") { |
| 482 | return endpoint.url; |
| 483 | } |
| 484 | |
| 485 | const apiURL = new URL(apiUrl); |
| 486 | |
| 487 | // if the API is localhost and the hostname is localhost |
| 488 | if (apiURL.hostname === "localhost" && endpoint.hostname === "localhost") { |
| 489 | return `http://${endpoint.hostname}:${endpoint.port}`; |
| 490 | } |
| 491 | |
| 492 | const triggerApi = new TriggerApi(apiKey, apiUrl); |
| 493 | |
| 494 | const supportsTunneling = await triggerApi.supportsTunneling(); |
| 495 | |
| 496 | if (supportsTunneling) { |
| 497 | const tunnelSpinner = ora(`🚇 Creating Trigger.dev tunnel`).start(); |
| 498 | const tunnelUrl = await createNativeTunnel( |
| 499 | endpoint.hostname, |
| 500 | endpoint.port, |
| 501 | endpoint.https, |
| 502 | triggerApi, |
| 503 | tunnelSpinner |
| 504 | ); |
| 505 | |
| 506 | if (tunnelUrl) { |
| 507 | tunnelSpinner.succeed(`🚇 Trigger.dev tunnel ready`); |
| 508 | } |
| 509 | |
| 510 | return tunnelUrl; |
| 511 | } else { |
| 512 | // Setup tunnel |
| 513 | const tunnelSpinner = ora(`🚇 Creating tunnel`).start(); |
| 514 | const tunnelUrl = await createNgrokTunnel(endpoint.hostname, endpoint.port, tunnelSpinner); |
| 515 | |
| 516 | if (tunnelUrl) { |
| 517 | tunnelSpinner.succeed(`🚇 Created tunnel: ${tunnelUrl}`); |
| 518 | } |
| 519 | |
| 520 | return tunnelUrl; |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | let yaltTunnel: YaltTunnel | null = null; |
| 525 |
no test coverage detected
searching dependent graphs…