firebase 3.16.0
Working on a Angular Universal Application with Firebase Function SSR support.
Everything works and the server renders all pages server-side (http://www.examples.com/foo http://www.examples.com/foo/bar), but not the home "/" (like http://www.examples.com/) page.
{
"hosting": {
"public": "dist/browser",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"function": "ssrapp"
}
]
},
"functions": {
"source": "functions"
}
}
By checking the source and the log files I have seen, that the function is never called on http://www.examples.com/. simple test by adding a console.log on the app.component.ts file inside angular. Log is present in all sub-pages, but not home.
I tried adding empty source to the firebase.json, but nothing works.
{
"source": "",
"function": "ssrapp"
},
or
{
"source": "/", >> even crashes deploy >> see log
"function": "ssrapp"
},
Firebase Functions should be able to route all pages of an SPA, especially for Angular Universal.
Error: HTTP Error: 400, hosting.rewrites[0] is not exactly one from [subschema 0],[subschema 1] for "source": "/"
besides that no error in console.
@denisyilmaz Why did you close this? I'm facing the same issue, how did you solve it?
I found the solution here : https://github.com/firebase/firebase-functions/issues/27
@denisyilmaz Sorry but was the solution ?
"rewrites": [
{
"source": "**",
"function": "ssrapp"
}
]
do not trigger my cloud function
@alexdabast delete your index.html from inside your /dist/browser folder then try ;)
Brilliant @gamebenchjake. Just saved my ass!
@gamebenchjake - That does solve the issue of the function not getting hit for the root, however it imposes many other limitations.
I am trying to create a bot interceptor in my cloud functions and return the pre-rendered content to the bot so that it can get the meta tags and SEO information. I am using rendertron for this and it works for all except the root.
By removing the index.html, the cloud function executes, but now there is no content to render. Also, users can no longer render the page in the browser.
How would I go about this if I still wish to have an index.html file for end users and rendertron?
@alexdabast deleting the index.html file from dist/browser and then running the app throw this error: "Failed to lookup view "index" in views directory "/srv/dist....".
Hi everyone, I have same issue, so can someone help me, I don't get what should I do. Tried: 1) delete index.html, but got error of @pranav96vaidya 2) "source": "", but got nothing; 3) another solutions, but already wasted 1/2 day or more :) (first time using Universal and Firebase Functions)
firebase.json
...
"rewrites": [
{
"source": "**",
"function": "ssr"
}
]
...
functions/src/index.ts
import * as functions from 'firebase-functions';
const universal = require(`${process.cwd()}/dist/server.js`).app;
export const ssr = functions.https.onRequest(universal);
server.ts
// All regular routes use the Universal engine
app.get('**', (req, res) => {
res.render('index', { req });
});
Hey @abzalzhumabaev , may be you can find this link (https://stackoverflow.com/questions/59153803/meta-tags-are-not-updating-for-root-url-www-domain-com/59280014#59280014) useful.
Hey @abzalzhumabaev , may be you can find this link (https://stackoverflow.com/questions/59153803/meta-tags-are-not-updating-for-root-url-www-domain-com/59280014#59280014) useful.
Thanks, it's actually helped :)
Most helpful comment
@alexdabast delete your index.html from inside your /dist/browser folder then try ;)