Trying to return a server-side response using Koa context, but not working on production

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 =[];
  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.


Hi @kevin ,

did you read over this?


Hi @codemonkeynorth ,

Thank you! I actually missed that, so thanks for pointing that out. I’ve tried one suggestion there, that is using ctx.respond = false to bypass Koa, before returning ctx.res.send(), but unfortunately that doesn’t work either. Moreover, I can’t generate Stripe session id on the client as that would expose the secret key.

So it seems that I have to not use Frontity to run the server-side function as there’s no way to return a response to the client side (at least for now). I thought I was very close to making this work :sweat_smile:

More suggestions are welcome, though! Thanks!