exports.host = functions.https.onRequest((req, res) => {
	const userAgent = req.headers['user-agent'].toLowerCase();
	let indexHTML = fs.readFileSync('./hosting/index.html').toString();
	const path = req.path ? req.path.split('/') : req.path;
	const ogPlaceholder = '';
	const metaPlaceholder = '';
	const isBot = userAgent.includes('googlebot') ||
		userAgent.includes('yahoou') ||
		userAgent.includes('bingbot') ||
		userAgent.includes('baiduspider') ||
		userAgent.includes('yandex') ||
		userAgent.includes('yeti') ||
		userAgent.includes('yodaobot') ||
		userAgent.includes('gigabot') ||
		userAgent.includes('ia_archiver') ||
		userAgent.includes('facebookexternalhit') ||
		userAgent.includes('twitterbot') ||
		userAgent.includes('developers\.google\.com') ? true : false;
	if (isBot && (path && path.length > 1 && path[1] === 'organisation')) {
		const slug = path[2];
		admin.database().ref(`published/${slug}`).once('value').then(snapshot => {
			const org = snapshot.val();
			if (org) {
				org.slug = slug;
			}
			indexHTML = indexHTML.replace(metaPlaceholder, getMeta(org));
			indexHTML = indexHTML.replace(ogPlaceholder, getOpenGraph(org));
			res.status(200).send(indexHTML);
		});
		return;
	}
	// optional - turn on caching: res.set('Cache-Control', 'public, max-age=300, s-maxage=600');
	indexHTML = indexHTML.replace(metaPlaceholder, getMeta());
	indexHTML = indexHTML.replace(ogPlaceholder, getOpenGraph());
	res.status(200).send(indexHTML);
});
const defaultDesc = 'The mobsters, bootleggers and gangsters of the 1920s and 30s, such as Al Capone, Lucky Luciano, and Bugs Moran.';
const defaultTitle = 'Original Gangsters';
const defaultLogo = 'https://example.com/images/headerHQ.jpg';
const getOpenGraph = (org) => {
	let og = ``;
	og += ``;
	if (!org) {
		og += ``;
		og += ``;
		og += ``;
		og += ``;
		return og;
	}
	og += ``;
	og += ``;
	og += ``;
	og += ``;
	return og;
};
const getMeta = (org) => {
	// return other meta tags
};