1.0.2 • Published 3 years ago

@glenstack/cf-workers-algolia-search v1.0.2

Weekly downloads
6
License
MIT
Repository
github
Last release
3 years ago

Cloudflare Workers Algolia Search

An Algolia search client for Cloudflare Workers.

Installation

npm install --save @glenstack/cf-workers-algolia-search

Usage

import algoliasearch from "@glenstack/cf-workers-algolia-search";

const client = algoliasearch("ApplicationID", "APIKey");
const index = client.initIndex("IndexName");

const handleRequest = async (request) => {
  const term = request.searchParams.get("term");
  const { hits } = await index.search(term);

  return new Response(JSON.stringify(hits), {
    headers: { "Content-Type": "application/json" },
  });
};

addEventListener("fetch", (event) => {
  const { request } = event;
  event.respondWith(handleRequest(request));
});

algoliasearch is an implementation of the official Algolia search client, so reference its documentation. Note however, that timeouts are not respected.