I’m trying to use Stripe on Node server with Frontity, and would like to return to the client some data (in this case session_id
). I’m using beforeSSR
action to create a custom route. I was able to return the value using return ctx.res.send({ someData })
on development, but when deployed to Vercel, this action returns 500 Internal Server Error.
Here’s what I’m trying to do on beforeSSR
:
// server.js
beforeSSR: ({ state, actions, libraries }) => async({ ctx }) => {
const data = state.source.data[state.router.link];
if (data.route === '/create-checkout-session/') {
const sessionId = await createStripeCheckoutSession(); // my function to get Stripe session ID
return ctx.res.send({ sessionId }); // works on development, but 500 Internal server error on production
}
}
Is there a better way to achieve this? That is, to send data back to the client from the server.
Thanks!