'`express.redirect` on GCP Cloud Function won't redirect using Google Chrome

I've got an express-based function deployed as GCP Cloud Function. I'd like to redirect to an external website in one of my routes. Consider my following code:

apiRouter.use(
  "/docs/asyncapi",
  asyncHandler(async (req, res) => {
    const asyncapi = await createUnifiedApi("./src/schemas/asyncapi.yml");
    // digging into AsyncAPI Studio code, we can utilize query params
    // https://github.com/asyncapi/studio/blob/150b7ad148459715bb97138a9af98e8d39032889/src/services/navigation.service.ts#L71
    const params = new URLSearchParams({
      readOnly: "true",
      base64: Buffer.from(JSON.stringify(asyncapi)).toString("base64"),
    }).toString();
    res.redirect("https://studio.asyncapi.com/?" + params);
  }),
);

When testing via functions-framework and Google Chrome, everything works correctly. When deploying, I'm getting Found. Redirecting to ... web-page where no redirection ever happens. See the following:

enter image description here

Going to Chrome DevTools, this is the response I'm getting when the redirection works:

enter image description here

And this is when it doesn't:

enter image description here

The main difference is the Location header that for some reason gets omitted when accessing the deployed function.

I'll add that this GCP Function is publicly available, and that I've also added cors middleware for express. How do I fix this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source