Using compute in product route

I wonder if there’s some negative implications using .compute in a regular product route, for example something like this

    .get('/products/:slug*', res => {
      res.compute(req => {
        const destination = getDestination(req.path);

        if (destination) {
          // if there's some redirect found for this page, do it
          res.cache({ edge: { maxAgeSeconds: FAR_FUTURE_TTL } });
          return res.redirect(
        } else {
          // otherwise just render PDP

this code works, but I’m not sure if this is the best way to handle some specific product redirects.


In this case, no, there won’t be any negative implications. I’m assuming that your previous iteration already used renderNuxtPage in this route, which means you were already using the serverless cloud to generate a response. Wrapping it with compute and some extra logic to handle redirects doesn’t add any additional latency beyond the time it takes to actually process the getDestination(path) call.

Previously it was

.get('/products/:slug*', ({ cache }) => cache(HTML))

but compute requires returning a response, so I’ve added renderNuxtPage in else