File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed
app/api/webhooks/trigger/[path] Expand file tree Collapse file tree 2 files changed +34
-0
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,6 +124,11 @@ export async function POST(
123124 return authError
124125 }
125126
127+ const reachabilityResponse = handleProviderReachabilityTest ( foundWebhook , body , requestId )
128+ if ( reachabilityResponse ) {
129+ return reachabilityResponse
130+ }
131+
126132 let preprocessError : NextResponse | null = null
127133 try {
128134 preprocessError = await checkWebhookPreprocessing ( foundWorkflow , foundWebhook , requestId )
Original file line number Diff line number Diff line change @@ -121,6 +121,34 @@ export async function handleProviderChallenges(
121121 return null
122122}
123123
124+ /**
125+ * Handle provider-specific reachability tests that occur AFTER webhook lookup.
126+ *
127+ * @param webhook - The webhook record from the database
128+ * @param body - The parsed request body
129+ * @param requestId - Request ID for logging
130+ * @returns NextResponse if this is a verification request, null to continue normal flow
131+ */
132+ export function handleProviderReachabilityTest (
133+ webhook : any ,
134+ body : any ,
135+ requestId : string
136+ ) : NextResponse | null {
137+ const provider = webhook ?. provider
138+
139+ if ( provider === 'grain' ) {
140+ const isVerificationRequest = ! body || Object . keys ( body ) . length === 0 || ! body . type
141+ if ( isVerificationRequest ) {
142+ logger . info (
143+ `[${ requestId } ] Grain reachability test detected - returning 200 for webhook verification`
144+ )
145+ return NextResponse . json ( { status : 'ok' , message : 'Webhook endpoint verified' } )
146+ }
147+ }
148+
149+ return null
150+ }
151+
124152export async function findWebhookAndWorkflow (
125153 options : WebhookProcessorOptions
126154) : Promise < { webhook : any ; workflow : any } | null > {
You can’t perform that action at this time.
0 commit comments