Skip to content

Latest commit

 

History

History
83 lines (50 loc) · 2.33 KB

README.md

File metadata and controls

83 lines (50 loc) · 2.33 KB

Redirect Cloud Function for Amazon Ratings

This repository contains a Firebase Cloud Function designed to perform geographical redirection based on the user's IP address. It's particularly useful for redirecting users to domain-specific pages or services, ensuring that they reach the most relevant content based on their location.

You can deploy this function and once a user, who bought a book on Amazon clicks on the link, they will be reidrected to the correct Amazon Store (US, DE, FR, ...) based on their IP address or langauge. Default always forwards to amazon.com

Tip: Use a QR code so the user can scan even easier.

Functionality

The geoRedirect function:

  • Checks if the domain making the request is allowed.
  • Retrieves the user's IP address.
  • Determines the user's geographical location using the geoip-lite library.
  • Redirects the user to a specific URL based on their country, with a fallback to a default domain.

Setup

Prerequisites

  • Node.js
  • Firebase CLI
  • A Firebase project

Installation

  1. Clone the repository:

    git clone https://github.com/bjoentrepreneur/amazon-review-redirect.git
    cd amazon-review-redirect
  2. Navigate to the functions directory:

   cd functions
  1. Istall dependencies:
   npm install

Configuration

  • Update the allowedDomains array in the index.js file to include the domains that are allowed to access this function.
  • Modify the countryDomainMapping object to map countries to specific domains as needed.

Deployment

Deploy the function to Firebase using the following command:

firebase deploy --only functions

Usage

Make a request to the deployed function's URL with the appropriate headers and query parameters:

  • x-forwarded-for: User's IP address.
  • asin: The Amazon Standard Identification Number.
  • language: (Optional) Fallback language parameter.

Disclaimer

This project is not affiliated with or endorsed by Amazon or any other domain-specific services used in the function.

Contributing

Contributions, issues, and feature requests are welcome. Feel free to check Issues if you want to contribute.

License

MIT

Contact

For any queries or contributions, please contact Björn