Firebase hosting : Detect social media crawler bots like facebook, twitter and google

Viewed 689

I have firebase hosting setup currently redirecting to index.html like this.

{
  "database": {
    "rules": "database.rules.json"
  },
  "hosting": {
    "public": "build",
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      },
      {
        "source": "/details/**",
        "function": "details"
      }
    ]
  }
}

But I want to redirect the request based on user-agents like Facebot for Facebook ...

Is there a way to redirect request on firebase hosting before reaching on cloud function? I know it's possible inside the function but I would love to do it on the hosting configuration.

1 Answers

I finally managed to solve this by creating a cloud function that redirects the bot request. You can identify the bot using the request's user agent.

Related