Remember that Redwood is focused on the JAMstack, so the web site is totally static and served from a CDN—there’s no server to handle webhooks or do any traditional “server” work.
However, any functions you create in the api side will be available to the internet. If you deploy to Netlify, then a function you create at api/src/functions/webhook.js will be available to the internet at https://mysite.netlify.com/.netlify/functions/webhook
Check out the Netlify Functions documentation for how to format those: https://docs.netlify.com/functions/build-with-javascript/#format Functions are deployed on AWS Lambda so they’re subject to all the limitations there (file size, total run time, etc). The simplest one you could create would look something like:
You can have the function read/write from your database by importing the PrismaClient and then writing queries. Although it isn’t written as a function, check out api/prisma/seeds.js for an example of using PrismaClient from scratch, without the Redwood graphql helpers.
If you run into any issues let me know! I struggled for a while wrapping my head around learning serverless + React + graphQL + Prisma all simultaneously so I understand how hard it can be getting started. No question is too basic.
I can’t find it in the docs now, but when working with Prisma it’s much easier to write your function handler as an async version rather than the callback version (callback version is in the code snippet above). The async version looks like:
Then you can do await and async with the PrismaClient calls and everything should work much smoother than trying to shoehorn everything into a callback function.
Only thing I’m not sure about is whether i need to close the db connection but i guess in a lambda it doesn’t really matter.
This works fine locally. I could not confirm whether it works with netlify yet. I have an error there, but not sure it’s really related to the hook + githubt is down.
Yup, without proper configuration an unclosed connection to your DB could be kept open & idle on the DB side for days, and even keep some locks active on some data or tables.
I deployed my project on Vercel but I don’t know where to get my webhook URL. Please how I can know my webhook URL if a save the webhook file in ‘…api/src/functions/’ ?