( resolvedOptions: ResolvedOptions, endpointId: string, apiKey: string, framework?: Framework )
| 371 | } |
| 372 | |
| 373 | async function verifyEndpoint( |
| 374 | resolvedOptions: ResolvedOptions, |
| 375 | endpointId: string, |
| 376 | apiKey: string, |
| 377 | framework?: Framework |
| 378 | ) { |
| 379 | const serverUrls = findServerUrls(resolvedOptions, framework); |
| 380 | |
| 381 | //try each url |
| 382 | for (const serverUrl of serverUrls) { |
| 383 | const protocol = resolvedOptions.https ? "https" : "http"; |
| 384 | const url = |
| 385 | serverUrl.type === "tunnel" |
| 386 | ? serverUrl.url |
| 387 | : `${protocol}://${serverUrl.hostname}:${serverUrl.port}`; |
| 388 | const localEndpointHandlerUrl = `${url}${resolvedOptions.handlerPath}`; |
| 389 | |
| 390 | const spinner = ora( |
| 391 | `[trigger.dev] Looking for your trigger endpoint: ${localEndpointHandlerUrl}` |
| 392 | ).start(); |
| 393 | |
| 394 | try { |
| 395 | const agent = new https.Agent({ |
| 396 | rejectUnauthorized: false, // Ignore self-signed certificates |
| 397 | }); |
| 398 | |
| 399 | // Conditionally include the agent in fetch options |
| 400 | const fetchOptions: RequestInit = { |
| 401 | method: "POST", |
| 402 | headers: { |
| 403 | "x-trigger-api-key": apiKey, |
| 404 | "x-trigger-action": "PING", |
| 405 | "x-trigger-endpoint-id": endpointId, |
| 406 | }, |
| 407 | ...(resolvedOptions.https && { agent }), |
| 408 | }; |
| 409 | |
| 410 | const response = await fetch(localEndpointHandlerUrl, fetchOptions); |
| 411 | |
| 412 | if (!response.ok || response.status !== 200) { |
| 413 | spinner.fail( |
| 414 | `[trigger.dev] Server responded with ${response.status} (${localEndpointHandlerUrl}).` |
| 415 | ); |
| 416 | continue; |
| 417 | } |
| 418 | |
| 419 | spinner.succeed(`[trigger.dev] Found your trigger endpoint: ${localEndpointHandlerUrl}`); |
| 420 | |
| 421 | return { |
| 422 | ...serverUrl, |
| 423 | handlerPath: resolvedOptions.handlerPath, |
| 424 | https: resolvedOptions.https ?? false, |
| 425 | }; |
| 426 | } catch (err) { |
| 427 | spinner.fail(`[trigger.dev] No server found (${localEndpointHandlerUrl}).`); |
| 428 | } |
| 429 | } |
| 430 |
no test coverage detected
searching dependent graphs…