-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
[REQUIRED] Environment info
firebase-tools: 7.9.0
Platform: Linux (Fedora 29)
[REQUIRED] Test case
Request URLs are used in the SSR (angular-universal) for navigation it seems that there is a breaking change in how they are handled by function emulator.
The last version I verified that doesn't have this issue is firebase-tools@6.8.0
.
From what I identified the problem seems to be related to request URLs. If I log the values I see
app.get('*', (req: express.Request, res: express.Response) => {
console.log(req.url, req.baseUrl, req.originalUrl);
// '/en/contact' '/web/us-central1/ssr' '/web/us-central1/ssr/en/contact'
res.render('web-index', { req, res });
});
But in case of the older versions of firebase-tools
let's say the version 6.8.0
, output for the same code will be '/en/contact', '', '/en/contact'
.
[REQUIRED] Steps to reproduce
Create a firebase function with minimal express setup and log the request object.
[REQUIRED] Expected behavior
URLs probably shouldn't be prefixed by the function base.
As a quick fix, I'm using replacing the prefix with request.baseUrl as a base should represent the prefix, but I'm not sure if it is the case in every possible scenario.
app.get('*', (req: express.Request, res: express.Response) => {
req.originalUrl = req.originalUrl.replace(req.baseUrl, '');
res.render('web-index', { req, res });
});
Another fix that may be a nicer solution is to explicitly set the url
string.
res.render('web-index', { req, res, url: req.url });
[REQUIRED] Actual behavior
URLs are prefixed by the function base. Router inside the universal rendering doesn't recognize the routes correctly and renders the default page.
As already mentioned in #1279 it seems like a breaking change that should be eighter corrected or documented.