Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for optionally requesting, receiving, and validating webhooks #102

Merged
merged 11 commits into from
May 13, 2024

Conversation

zeke
Copy link
Member

@zeke zeke commented May 13, 2024

Replaces #99 with an updated approach using Next.js app router with proper Request and Response objects.

Docs: https://github.com/replicate/getting-started-nextjs/tree/webhook-validation-on-app-router#webhooks

To Do

  • Make webhooks optional
  • Make webhook validation optional
  • Document how to test webhooks locally (ngrok, signing secret, etc)
  • Maybe update the whole app to use Next.js App router so the req vs Request shenanigans go away?

@zeke zeke mentioned this pull request May 13, 2024
3 tasks
@zeke zeke requested review from a team May 13, 2024 16:50
@zeke zeke changed the title Webhook validation on app router add support for optionally requesting, receiving, and validating webhooks May 13, 2024
return NextResponse.json({ detail: "Webhook received (but not validated)" }, { status: 200 });
}

const webhookIsValid = await validateWebhook(request.clone(), secret);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm doing this request.clone() business here because you can only read the request body once in Next.js API routes. Without this change, you'll get TypeError: Body is unusable when calling request.json() after validation.

@mattt what do you think of this?

@zeke zeke requested review from mattt and aron May 13, 2024 16:54
@zeke zeke force-pushed the webhook-validation-on-app-router branch from 908d672 to beba5b8 Compare May 13, 2024 17:25
Update README.md

Update README.md

move the iguana

Update README.md

rearrange webhooks docs

Update README.md
@zeke zeke force-pushed the webhook-validation-on-app-router branch from beba5b8 to db584f4 Compare May 13, 2024 17:27
Copy link

@deepfates deepfates left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this looks quite reasonable to solve this issue! only nitpick, do I need ngrok for the production environment or just for dev servers? I don’t think the documentation makes it clear as is. but might be a me issue

@zeke
Copy link
Member Author

zeke commented May 13, 2024

do I need ngrok for the production environment or just for dev servers?

Just for dev. Good shout. Updated in 863a91a

@zeke zeke merged commit 50432ce into main May 13, 2024
1 check passed
@zeke zeke deleted the webhook-validation-on-app-router branch May 13, 2024 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants