@glenstack/cf-workers-algolia-search
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

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.

Readme

Keywords

none

Package Sidebar

Install

npm i @glenstack/cf-workers-algolia-search

Weekly Downloads

1,144

Version

1.0.2

License

MIT

Unpacked Size

28.1 kB

Total Files

7

Last publish

Collaborators

  • gregbrimble