Last active
February 25, 2018 17:38
-
-
Save EliaECoyote/9e86e46d16c366b9f9c72009c8165087 to your computer and use it in GitHub Desktop.
Revisions
-
EliaECoyote revised this gist
Feb 25, 2018 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -35,6 +35,7 @@ const nodeFetchConfig = { app.get('/events/:id', (request, response) => { const userAgent = request.get('user-agent'); if (userAgent.indexOf("facebookexternalhit") === 0) { const endpoint = `${apiEndpoint}/ev/${request.params.id}`; fetch(apiEndpoint, nodeFetchConfig) .then(res => res.json()) .then(json => json.data) -
EliaECoyote created this gist
Feb 25, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,59 @@ import * as functions from 'firebase-functions'; import * as express from 'express'; const app = express(); function buildOgTemplate(event: any) { return ` <!DOCTYPE html> <html> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8"/> <meta property="og:title" content="${event.title}" /> <meta property="og:description" content="${event.description}" /> <meta property="og:url" content="https://socialevents.com" /> <meta property="og:image" content="${event.image}" /> <meta property="og:type" content="website" /> <meta property="og:image:width" content="600" /> <meta property="og:image:height" content="600" /> <base href="/"> </head> </html> ` } const publicEndpoint = "https://socialevents.com" const apiEndpoint = "https://api.socialevents.com/api/v1" const nodeFetchConfig = { headers: { "Accept": "application/json", "Cache-Control": "no-cache" } }; app.get('/events/:id', (request, response) => { const userAgent = request.get('user-agent'); if (userAgent.indexOf("facebookexternalhit") === 0) { fetch(apiEndpoint, nodeFetchConfig) .then(res => res.json()) .then(json => json.data) .then(event => { const template = buildTemplateWithMetas(event) response.status(200).send(template); }) .catch(error => fetch(`${publicEndpoint}/index.html`) .then(res => res.text()) .then(html => response.status(200).send(html)) .catch(err => response.send(err)); ); } else { fetch(`${config.publicEndpoint}/index.html`) .then(res => res.text()) .then(html => response.send(html)) .catch(error => response.send(error)); } }); exports.eventsReqHandler = functions.https.onRequest(app);