Request URLs are prefixed with the function "path"
See original GitHub issue[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.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:7 (3 by maintainers)
Ok I finally got around to taking another look at this one. Here’s the function I wrote to reproduce:
In Emulator
In Production
So it looks like
url
is correct butbaseUrl
andoriginalUrl
both contain an unnecessary prefix of/ota-fir-dumpster/us-central1/app
… I’ll look at how to remove that now.@charles-allen I can totally see your use cases but our goal here is in this repo is simple: create emulators which locally match the behavior of Google Cloud Functions in production.
I can’t offer any insight as to why GCF paths are the way they are, that sort of decision is a few years old and was made before these emulators existed! Changing it would be really disruptive so I think we’ll have to live with the current behavior.