Skip to content

Commit 86bcdcf

Browse files
authored
fix(grain): save before deploying workflow (#2678)
* save before deployment fix * moved to helper * removed comment
1 parent ac94241 commit 86bcdcf

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

apps/sim/app/api/webhooks/trigger/[path]/route.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
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)

apps/sim/lib/webhooks/processor.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
124152
export async function findWebhookAndWorkflow(
125153
options: WebhookProcessorOptions
126154
): Promise<{ webhook: any; workflow: any } | null> {

0 commit comments

Comments
 (0)