How to test and debug a bot request that triggers a cloud functionHow to request Google to re-crawl my website?Do all search bots use escaped fragment?Cloud Functions for Firebase trigger on time?I'm using ng2-metadata with my angular version 4 app and google only seems to show the default title and descriptionHow to use Cloud Functions for Firebase to prerender pages for SEO?Redirect Firebase Hosting root to a Cloud Function is not workingFirebase dynamic hosting with Angular 2Cloud Functions: Firestore triggersUsing a firebase cloud function for SEO at root levelFetchError - Server-side rendering with Rendertron - Firebase & Angular 5

What should I wear to go and sign an employment contract?

Working hours and productivity expectations for game artists and programmers

Taylor series leads to two different functions - why?

Is there any deeper thematic meaning to the white horse that Arya finds in The Bells (S08E05)?

When did Britain learn about the American Declaration of Independence?

FIFO data structure in pure C

Should all adjustments be random effects in a mixed linear effect?

Sort a section of a file

Gaussian kernel density estimation with data from file

Parse a C++14 integer literal

Was Tyrion always a poor strategist?

how to create an executable file for an AppleScript?

Are there any symmetric cryptosystems based on computational complexity assumptions?

Who is frowning in the sentence "Daisy looked at Tom frowning"?

How does this piece of code determine array size without using sizeof( )?

What's is the easiest way to purchase a stock and hold it

Why are stats in Angband written as 18/** instead of 19, 20...?

What color to choose as "danger" if the main color of my app is red

Lock out of Oracle based on Windows username

How can I monitor the bulk API limit?

RegEx with d doesn’t work in if-else statement with [[

Does the talk count as invited if my PI invited me?

Why is so much ransomware breakable?

Will this series of events work to drown a tarrasque?



How to test and debug a bot request that triggers a cloud function


How to request Google to re-crawl my website?Do all search bots use escaped fragment?Cloud Functions for Firebase trigger on time?I'm using ng2-metadata with my angular version 4 app and google only seems to show the default title and descriptionHow to use Cloud Functions for Firebase to prerender pages for SEO?Redirect Firebase Hosting root to a Cloud Function is not workingFirebase dynamic hosting with Angular 2Cloud Functions: Firestore triggersUsing a firebase cloud function for SEO at root levelFetchError - Server-side rendering with Rendertron - Firebase & Angular 5






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















The Problem



I'm building a angular pwa and I wanted to do some basic seo optimizing on it. I set up the meta tags to change when you navigate to different routes in the application by using a seo service. Then I made a firebase cloud function that use the functions.https.onRequest(myFunction) to check if the request is from a bot and if so send it to rendertron if not it sends the user to my page.



I think something is wrong with my firebase cloud function. Its either not detecting bot requests or its not properly sending the request to rendertron, but I'm not sure how to debug this.



What I tried was using firebase serve to simulate a user requesting the page and everything works fine. I'm just not sure how to simulate a bot requesting the page locally so I can see whats going on. I tried deploying the function and testing it by sharing it on facebook but the facebook preview only seems to see the initial meta tags not the tags that have been changed.



The seo Service



The service appears to work fine. I just thought I'd include this so you could get an idea of how I'm dynamically changing my meta tags.



import Injectable from '@angular/core';
import Meta from '@angular/platform-browser';
import SeoConfig from '../interfaces/seo-config.interface';

@Injectable(
providedIn: 'root'
)
export class SeoService {

constructor(private meta: Meta)

generateTags(config: SeoConfig)
config =
title: 'my default site title here...',
description: 'my default description here...',
image: 'my default path to image here...',
slug: '',
...config

this.meta.updateTag( property: 'og:title', content: config.title);
this.meta.updateTag( property: 'og:description', content: config.description);
this.meta.updateTag( property: 'og:image', content: config.image);
this.meta.updateTag( property: 'og:url', content:`https://paradigmShift.app/$config.slug`);
this.meta.updateTag( name: 'twitter:card', content: 'summary_large_image');



The firebase cloud function



This is where I suspect the problem is



const functions = require('firebase-functions');
const express = require('express');
const fetch = require('node-fetch');
const url = require('url');
const app = express();
const cors = require('cors')

const appUrl = 'my domain here';
const renderUrl = 'https://render-tron.appspot.com/render';

function generateUrl(request)
return url.format(
protocol: request.protocol,
host: appUrl,
pathname: request.originalUrl
);


function detectBot(userAgent) W3C_Validator

app.use(cors());

app.get('*',(req, res) =>
const isBot = detectBot(req.headers['user-agent']);
if (isBot)
const botUrl = generateUrl(req);
console.log('bot detected', botUrl);
fetch(`$renderUrl/$botUrl`)
.then(res => res.text())
.then(body =>
res.set('Cache-Control', 'public, max-age=300, s-maxage=600');
res.set('Very', 'User-Agent');
res.send(body.toString());
);
else
console.log('no bot detected', appUrl);
fetch(`$appUrl`)
.then(res => res.text())
.then(body =>
console.log(body.toString());
res.send(body.toString());
);

);

exports.app = functions.https.onRequest(app);


If you can spot any errors in my code or cloud function that would be great. If not, what I'm looking for is a method for debugging the function when a bot requests the page.










share|improve this question
























  • I don't quite understand the problem you're running into. You trigger the function by making an HTTP request. There are lots of ways to do this.

    – Doug Stevenson
    Mar 23 at 17:05











  • I guess im just not understanding how to make a http request form a bot.

    – James
    Mar 23 at 17:22












  • That's pretty vague. What do you mean by "from a bot"? There's got to be dozens of types of bots out there.

    – Doug Stevenson
    Mar 23 at 17:53











  • There's a list of the bots I'm interested in stored in the const botList within the detectBot function. Basically social media sites like twitterbot.

    – James
    Mar 23 at 18:03






  • 1





    You're going to have to narrow down your question to a single issue rather than asking for a list of implementations for all these bots.

    – Doug Stevenson
    Mar 23 at 18:20

















0















The Problem



I'm building a angular pwa and I wanted to do some basic seo optimizing on it. I set up the meta tags to change when you navigate to different routes in the application by using a seo service. Then I made a firebase cloud function that use the functions.https.onRequest(myFunction) to check if the request is from a bot and if so send it to rendertron if not it sends the user to my page.



I think something is wrong with my firebase cloud function. Its either not detecting bot requests or its not properly sending the request to rendertron, but I'm not sure how to debug this.



What I tried was using firebase serve to simulate a user requesting the page and everything works fine. I'm just not sure how to simulate a bot requesting the page locally so I can see whats going on. I tried deploying the function and testing it by sharing it on facebook but the facebook preview only seems to see the initial meta tags not the tags that have been changed.



The seo Service



The service appears to work fine. I just thought I'd include this so you could get an idea of how I'm dynamically changing my meta tags.



import Injectable from '@angular/core';
import Meta from '@angular/platform-browser';
import SeoConfig from '../interfaces/seo-config.interface';

@Injectable(
providedIn: 'root'
)
export class SeoService {

constructor(private meta: Meta)

generateTags(config: SeoConfig)
config =
title: 'my default site title here...',
description: 'my default description here...',
image: 'my default path to image here...',
slug: '',
...config

this.meta.updateTag( property: 'og:title', content: config.title);
this.meta.updateTag( property: 'og:description', content: config.description);
this.meta.updateTag( property: 'og:image', content: config.image);
this.meta.updateTag( property: 'og:url', content:`https://paradigmShift.app/$config.slug`);
this.meta.updateTag( name: 'twitter:card', content: 'summary_large_image');



The firebase cloud function



This is where I suspect the problem is



const functions = require('firebase-functions');
const express = require('express');
const fetch = require('node-fetch');
const url = require('url');
const app = express();
const cors = require('cors')

const appUrl = 'my domain here';
const renderUrl = 'https://render-tron.appspot.com/render';

function generateUrl(request)
return url.format(
protocol: request.protocol,
host: appUrl,
pathname: request.originalUrl
);


function detectBot(userAgent) W3C_Validator

app.use(cors());

app.get('*',(req, res) =>
const isBot = detectBot(req.headers['user-agent']);
if (isBot)
const botUrl = generateUrl(req);
console.log('bot detected', botUrl);
fetch(`$renderUrl/$botUrl`)
.then(res => res.text())
.then(body =>
res.set('Cache-Control', 'public, max-age=300, s-maxage=600');
res.set('Very', 'User-Agent');
res.send(body.toString());
);
else
console.log('no bot detected', appUrl);
fetch(`$appUrl`)
.then(res => res.text())
.then(body =>
console.log(body.toString());
res.send(body.toString());
);

);

exports.app = functions.https.onRequest(app);


If you can spot any errors in my code or cloud function that would be great. If not, what I'm looking for is a method for debugging the function when a bot requests the page.










share|improve this question
























  • I don't quite understand the problem you're running into. You trigger the function by making an HTTP request. There are lots of ways to do this.

    – Doug Stevenson
    Mar 23 at 17:05











  • I guess im just not understanding how to make a http request form a bot.

    – James
    Mar 23 at 17:22












  • That's pretty vague. What do you mean by "from a bot"? There's got to be dozens of types of bots out there.

    – Doug Stevenson
    Mar 23 at 17:53











  • There's a list of the bots I'm interested in stored in the const botList within the detectBot function. Basically social media sites like twitterbot.

    – James
    Mar 23 at 18:03






  • 1





    You're going to have to narrow down your question to a single issue rather than asking for a list of implementations for all these bots.

    – Doug Stevenson
    Mar 23 at 18:20













0












0








0








The Problem



I'm building a angular pwa and I wanted to do some basic seo optimizing on it. I set up the meta tags to change when you navigate to different routes in the application by using a seo service. Then I made a firebase cloud function that use the functions.https.onRequest(myFunction) to check if the request is from a bot and if so send it to rendertron if not it sends the user to my page.



I think something is wrong with my firebase cloud function. Its either not detecting bot requests or its not properly sending the request to rendertron, but I'm not sure how to debug this.



What I tried was using firebase serve to simulate a user requesting the page and everything works fine. I'm just not sure how to simulate a bot requesting the page locally so I can see whats going on. I tried deploying the function and testing it by sharing it on facebook but the facebook preview only seems to see the initial meta tags not the tags that have been changed.



The seo Service



The service appears to work fine. I just thought I'd include this so you could get an idea of how I'm dynamically changing my meta tags.



import Injectable from '@angular/core';
import Meta from '@angular/platform-browser';
import SeoConfig from '../interfaces/seo-config.interface';

@Injectable(
providedIn: 'root'
)
export class SeoService {

constructor(private meta: Meta)

generateTags(config: SeoConfig)
config =
title: 'my default site title here...',
description: 'my default description here...',
image: 'my default path to image here...',
slug: '',
...config

this.meta.updateTag( property: 'og:title', content: config.title);
this.meta.updateTag( property: 'og:description', content: config.description);
this.meta.updateTag( property: 'og:image', content: config.image);
this.meta.updateTag( property: 'og:url', content:`https://paradigmShift.app/$config.slug`);
this.meta.updateTag( name: 'twitter:card', content: 'summary_large_image');



The firebase cloud function



This is where I suspect the problem is



const functions = require('firebase-functions');
const express = require('express');
const fetch = require('node-fetch');
const url = require('url');
const app = express();
const cors = require('cors')

const appUrl = 'my domain here';
const renderUrl = 'https://render-tron.appspot.com/render';

function generateUrl(request)
return url.format(
protocol: request.protocol,
host: appUrl,
pathname: request.originalUrl
);


function detectBot(userAgent) W3C_Validator

app.use(cors());

app.get('*',(req, res) =>
const isBot = detectBot(req.headers['user-agent']);
if (isBot)
const botUrl = generateUrl(req);
console.log('bot detected', botUrl);
fetch(`$renderUrl/$botUrl`)
.then(res => res.text())
.then(body =>
res.set('Cache-Control', 'public, max-age=300, s-maxage=600');
res.set('Very', 'User-Agent');
res.send(body.toString());
);
else
console.log('no bot detected', appUrl);
fetch(`$appUrl`)
.then(res => res.text())
.then(body =>
console.log(body.toString());
res.send(body.toString());
);

);

exports.app = functions.https.onRequest(app);


If you can spot any errors in my code or cloud function that would be great. If not, what I'm looking for is a method for debugging the function when a bot requests the page.










share|improve this question
















The Problem



I'm building a angular pwa and I wanted to do some basic seo optimizing on it. I set up the meta tags to change when you navigate to different routes in the application by using a seo service. Then I made a firebase cloud function that use the functions.https.onRequest(myFunction) to check if the request is from a bot and if so send it to rendertron if not it sends the user to my page.



I think something is wrong with my firebase cloud function. Its either not detecting bot requests or its not properly sending the request to rendertron, but I'm not sure how to debug this.



What I tried was using firebase serve to simulate a user requesting the page and everything works fine. I'm just not sure how to simulate a bot requesting the page locally so I can see whats going on. I tried deploying the function and testing it by sharing it on facebook but the facebook preview only seems to see the initial meta tags not the tags that have been changed.



The seo Service



The service appears to work fine. I just thought I'd include this so you could get an idea of how I'm dynamically changing my meta tags.



import Injectable from '@angular/core';
import Meta from '@angular/platform-browser';
import SeoConfig from '../interfaces/seo-config.interface';

@Injectable(
providedIn: 'root'
)
export class SeoService {

constructor(private meta: Meta)

generateTags(config: SeoConfig)
config =
title: 'my default site title here...',
description: 'my default description here...',
image: 'my default path to image here...',
slug: '',
...config

this.meta.updateTag( property: 'og:title', content: config.title);
this.meta.updateTag( property: 'og:description', content: config.description);
this.meta.updateTag( property: 'og:image', content: config.image);
this.meta.updateTag( property: 'og:url', content:`https://paradigmShift.app/$config.slug`);
this.meta.updateTag( name: 'twitter:card', content: 'summary_large_image');



The firebase cloud function



This is where I suspect the problem is



const functions = require('firebase-functions');
const express = require('express');
const fetch = require('node-fetch');
const url = require('url');
const app = express();
const cors = require('cors')

const appUrl = 'my domain here';
const renderUrl = 'https://render-tron.appspot.com/render';

function generateUrl(request)
return url.format(
protocol: request.protocol,
host: appUrl,
pathname: request.originalUrl
);


function detectBot(userAgent) W3C_Validator

app.use(cors());

app.get('*',(req, res) =>
const isBot = detectBot(req.headers['user-agent']);
if (isBot)
const botUrl = generateUrl(req);
console.log('bot detected', botUrl);
fetch(`$renderUrl/$botUrl`)
.then(res => res.text())
.then(body =>
res.set('Cache-Control', 'public, max-age=300, s-maxage=600');
res.set('Very', 'User-Agent');
res.send(body.toString());
);
else
console.log('no bot detected', appUrl);
fetch(`$appUrl`)
.then(res => res.text())
.then(body =>
console.log(body.toString());
res.send(body.toString());
);

);

exports.app = functions.https.onRequest(app);


If you can spot any errors in my code or cloud function that would be great. If not, what I'm looking for is a method for debugging the function when a bot requests the page.







angular seo google-cloud-functions






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 23 at 18:09







James

















asked Mar 23 at 17:02









JamesJames

237




237












  • I don't quite understand the problem you're running into. You trigger the function by making an HTTP request. There are lots of ways to do this.

    – Doug Stevenson
    Mar 23 at 17:05











  • I guess im just not understanding how to make a http request form a bot.

    – James
    Mar 23 at 17:22












  • That's pretty vague. What do you mean by "from a bot"? There's got to be dozens of types of bots out there.

    – Doug Stevenson
    Mar 23 at 17:53











  • There's a list of the bots I'm interested in stored in the const botList within the detectBot function. Basically social media sites like twitterbot.

    – James
    Mar 23 at 18:03






  • 1





    You're going to have to narrow down your question to a single issue rather than asking for a list of implementations for all these bots.

    – Doug Stevenson
    Mar 23 at 18:20

















  • I don't quite understand the problem you're running into. You trigger the function by making an HTTP request. There are lots of ways to do this.

    – Doug Stevenson
    Mar 23 at 17:05











  • I guess im just not understanding how to make a http request form a bot.

    – James
    Mar 23 at 17:22












  • That's pretty vague. What do you mean by "from a bot"? There's got to be dozens of types of bots out there.

    – Doug Stevenson
    Mar 23 at 17:53











  • There's a list of the bots I'm interested in stored in the const botList within the detectBot function. Basically social media sites like twitterbot.

    – James
    Mar 23 at 18:03






  • 1





    You're going to have to narrow down your question to a single issue rather than asking for a list of implementations for all these bots.

    – Doug Stevenson
    Mar 23 at 18:20
















I don't quite understand the problem you're running into. You trigger the function by making an HTTP request. There are lots of ways to do this.

– Doug Stevenson
Mar 23 at 17:05





I don't quite understand the problem you're running into. You trigger the function by making an HTTP request. There are lots of ways to do this.

– Doug Stevenson
Mar 23 at 17:05













I guess im just not understanding how to make a http request form a bot.

– James
Mar 23 at 17:22






I guess im just not understanding how to make a http request form a bot.

– James
Mar 23 at 17:22














That's pretty vague. What do you mean by "from a bot"? There's got to be dozens of types of bots out there.

– Doug Stevenson
Mar 23 at 17:53





That's pretty vague. What do you mean by "from a bot"? There's got to be dozens of types of bots out there.

– Doug Stevenson
Mar 23 at 17:53













There's a list of the bots I'm interested in stored in the const botList within the detectBot function. Basically social media sites like twitterbot.

– James
Mar 23 at 18:03





There's a list of the bots I'm interested in stored in the const botList within the detectBot function. Basically social media sites like twitterbot.

– James
Mar 23 at 18:03




1




1





You're going to have to narrow down your question to a single issue rather than asking for a list of implementations for all these bots.

– Doug Stevenson
Mar 23 at 18:20





You're going to have to narrow down your question to a single issue rather than asking for a list of implementations for all these bots.

– Doug Stevenson
Mar 23 at 18:20












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55316222%2fhow-to-test-and-debug-a-bot-request-that-triggers-a-cloud-function%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55316222%2fhow-to-test-and-debug-a-bot-request-that-triggers-a-cloud-function%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해