File tree Expand file tree Collapse file tree 2 files changed +35
-7
lines changed
app/api/webhooks/trigger/[path] Expand file tree Collapse file tree 2 files changed +35
-7
lines changed Original file line number Diff line number Diff line change 55 checkWebhookPreprocessing ,
66 findWebhookAndWorkflow ,
77 handleProviderChallenges ,
8+ handleProviderReachabilityTest ,
89 parseWebhookBody ,
910 queueWebhookExecution ,
1011 verifyProviderAuth ,
@@ -123,13 +124,9 @@ export async function POST(
123124 return authError
124125 }
125126
126- const isGrainVerificationRequest =
127- foundWebhook . provider === 'grain' && ( ! body || Object . keys ( body ) . length === 0 || ! body . type )
128- if ( isGrainVerificationRequest ) {
129- logger . info (
130- `[${ requestId } ] Grain verification request detected - returning 200 for reachability test`
131- )
132- return NextResponse . json ( { status : 'ok' , message : 'Webhook endpoint verified' } )
127+ const reachabilityResponse = handleProviderReachabilityTest ( foundWebhook , body , requestId )
128+ if ( reachabilityResponse ) {
129+ return reachabilityResponse
133130 }
134131
135132 let preprocessError : NextResponse | null = null
Original file line number Diff line number Diff line change @@ -121,6 +121,37 @@ export async function handleProviderChallenges(
121121 return null
122122}
123123
124+ /**
125+ * Handle provider-specific reachability tests that occur AFTER webhook lookup.
126+ *
127+ * This function should be called after findWebhookAndWorkflow() but before
128+ * checkWebhookPreprocessing() to allow verification requests to bypass deployment checks.
129+ *
130+ * @param webhook - The webhook record from the database
131+ * @param body - The parsed request body
132+ * @param requestId - Request ID for logging
133+ * @returns NextResponse if this is a verification request, null to continue normal flow
134+ */
135+ export function handleProviderReachabilityTest (
136+ webhook : any ,
137+ body : any ,
138+ requestId : string
139+ ) : NextResponse | null {
140+ const provider = webhook ?. provider
141+
142+ if ( provider === 'grain' ) {
143+ const isVerificationRequest = ! body || Object . keys ( body ) . length === 0 || ! body . type
144+ if ( isVerificationRequest ) {
145+ logger . info (
146+ `[${ requestId } ] Grain reachability test detected - returning 200 for webhook verification`
147+ )
148+ return NextResponse . json ( { status : 'ok' , message : 'Webhook endpoint verified' } )
149+ }
150+ }
151+
152+ return null
153+ }
154+
124155export async function findWebhookAndWorkflow (
125156 options : WebhookProcessorOptions
126157) : Promise < { webhook : any ; workflow : any } | null > {
You can’t perform that action at this time.
0 commit comments