firebase-tools icon indicating copy to clipboard operation
firebase-tools copied to clipboard

Angular SSR 17.2 feature conflicts with hosting rewrites

Open alexcibotari opened this issue 1 year ago • 2 comments

[REQUIRED] Environment info

firebase-tools: 13.4.0

Platform: Windows 11

[REQUIRED] Test case

I have the next firebase.json configuration :

{

"hosting": {
    "target": "example",
    "source": ".",
    "frameworksBackend": {
      "region": "europe-west1",
      "maxInstances": 1
    },
    "redirects": [
      {
        "source": "/",
        "destination": "/home",
        "type": 301
      }
    ],
    "rewrites": [
      {
        "source": "/api/**",
        "function": "api",
        "region": "europe-west6"
      }
    ]
  },

}

[REQUIRED] Steps to reproduce

Perform GET request to <firebase host>/api/users

[REQUIRED] Expected behavior

The request is receiving a response from the Firebase function

[REQUIRED] Actual behavior

The request is handled by Angular SSR frameworksBackend function

alexcibotari avatar Mar 08 '24 12:03 alexcibotari

Hey @alexcibotari, thanks for reaching out. Sorry to hear you’re encountering this issue. By any chance, would you be able to share a minimal reproducible example with us, or detailed steps on how you set up your Angular project? This will help us with replicating the issue.

aalej avatar Mar 08 '24 17:03 aalej

Hello @aalej

The most closest example that I have at the moment

https://codesandbox.io/p/devbox/naughty-wave-x4xqrs?file=%2Fsrc%2Fapp%2Fapp.routes.ts

alexcibotari avatar Mar 08 '24 18:03 alexcibotari

I had the same issue with Next.js

FYI: https://github.com/firebase/firebase-tools/blob/d9d51e4f06c00853d9329376aba27712abc8d6d6/src/frameworks/index.ts#L331

leach-mrt avatar Apr 04 '24 05:04 leach-mrt

Hi @alexcibotari,

Could you try to use the send method instead of return in the function? Like below:

const expressApp = express();
expressApp.use(cors({origin: true}));

expressApp.get("/api/users", async (req, res) => {
  logger.info("users : " + JSON.stringify(req.params));
  logger.info("users : " + JSON.stringify(req.query));
  return res.send({message: "hello world"});
});

export const api = onRequest(expressApp);

Please let me know if it helps.

9kubczas4 avatar Apr 08 '24 17:04 9kubczas4

Hello @9kubczas4 ,

the result is the same. The response is coming from the SSR function created by Firebase, and not the function associated with the path in hosting.

alexcibotari avatar Apr 08 '24 18:04 alexcibotari