I followed this tutorial https://hackernoon.com/firebase-to-the-rescue-dynamic-routing-via-hosting-functions-integration-aef888ddf311
and I put this snipit of code in the index.js in my backend folder.
when I share through twitter for example It never shows the image in the index.html but also it never shares the image specified in this function although when I go to the link specified the tweet It shows the updated meta but a blank page!!!
does this means I need to use firebase ssr???
function buildHtmlWithArticle (article) {
const string = ‘<!DOCTYPE html>\n’+
‘<html lang=“en” translate=“yes”> \n’+
‘<head> \n’+
‘<meta charset=“utf-8” /> \n’ +
‘<meta http-equiv=“X-UA-Compatible” content=“IE=edge” /> \n’+
‘<meta name=“viewport” content=“width=device-width,initial-scale=1.0” /> \n’ +
‘<meta http-equiv=“Content-Type” content=“text/html; charset=utf-8” /> \n’+
‘<meta http-equiv=“Content-Type” content=“text/html; charset=ISO-8859-1” /> \n’+
‘<meta NAME=“geo.position” CONTENT=“latitude; longitude”> \n’+
‘<meta NAME=“geo.placename” CONTENT=“Place Name”> \n’+
‘<meta NAME=“geo.region” CONTENT=“Country Subdivision Code”></meta> \n’+
‘<meta http-equiv=“Cache-control” content=“public”> \n’+
‘</body> \n’+
‘</html>’
return string;
}
exports.article = functions.https.onRequest( async (req, res) => {
console.log(‘in article function’)
console.log(‘path in req’,req.path)
const path = req.path.split(’/’);
console.log(‘path’,path)
const articleId = path[2];
const article = await admin
.firestore()
.doc(article/${articleId})
.get()
const item = Object.assign({}, article.data(), {
id: article.uri,
});
const htmlString = buildHtmlWithArticle(item);
console.log(‘html string’,htmlString)
res.status(200).end(htmlString);
});