Giter Site home page Giter Site logo

serverless-atomic-algolia's Introduction

Atomic Algolia Serverless

A serverless function for updating one or more Algolia indices from JSON endpoints using a simple Webtask function.

Installation

You must first have Node & NPM installed.

Once installed, run:

npm install serverless -g && npm install

Configuration

Before you can use this function, you need to authorize with the provider (Webtask by Auth0). This is extremely simple, just run:

serverless config credentials --provider webtasks

You will be asked for a phone number or email. You'll immediately receive a verification code. Enter the verification code and your profile will be entirely setup and ready to use.


This function needs the following to be configured:

  • A secrets.yml file with your Algolia Application ID and secret access key.
  • An indexes.js file with a list of your indexes and their JSON endpoints.

To create your secrets.yml file, run:

cp ./config/secrets.yml.stub ./config/secrets.yml

Then open up config/secrets.yml and provide the values for ALGOLIA_APP_ID and ALGOLIA_ADMIN_KEY from your Algolia account.

Next, open up config/indexes.js and update the example index with your actual Algolia index information. E.g,

[
    {
        name: "dist",
        url: "https://example.com/index.json"
    }
]

Usage

To deploy this function in development mode, run:

serverless deploy

To deploy this function with production secrets, run:

serverless deploy --stage prod --ALGOLIA_APP_ID=YOUR_APP_ID --ALGOLIA_ADMIN_KEY=YOUR_ADMIN_KEY

Creating a schedule

By default, this function will run every hour. You can update this as desired by opening up serverless.yml, and changing functions.main.events.schedule.

Triggering from a GitHub Webhook

When deploying the function, Serverless provides you with the Webtask endpoint that you can use to trigger the index update.

Head over to your GitHub repository, open up Settings, and then choose Webhooks from the sidebar.

  1. Choose Add Webhook, and set the webtask URL provided by Serverless as the Payload URL.
  2. Set the Content Type to JSON
  3. Select Let me select individual events
  4. Ensure only Push is selected
  5. Ensure Active is checked
  6. Click Add webhook

Now each time a change is pushed to your repository, this function will be triggered to deploy your Algolia index.

Note: Depending on how long your site takes to deploy, this may cause the index to be updated prematurely. To fix this, you can set the debounce variable in secrets.yml to make the function wait X number of seconds before running.

serverless-atomic-algolia's People

Contributors

chrisdmacrae avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.