File size: 863 Bytes
c09f67c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import type { Bindings } from "@engine/common/bindings";
import Typesense from "typesense";

export function SearchClient(envs: Bindings) {
  return new Typesense.Client({
    nearestNode: {
      host: envs.TYPESENSE_ENDPOINT!,
      port: 443,
      protocol: "https",
    },
    nodes: [
      { host: envs.TYPESENSE_ENDPOINT_US!, port: 443, protocol: "https" },
      { host: envs.TYPESENSE_ENDPOINT_EU!, port: 443, protocol: "https" },
      { host: envs.TYPESENSE_ENDPOINT_AU!, port: 443, protocol: "https" },
    ],
    apiKey: envs.TYPESENSE_API_KEY,
    connectionTimeoutSeconds: 2,
  });
}

export async function getHealthCheck(envs: Bindings) {
  const typesense = SearchClient(envs);
  const searchResponse = await typesense.health.retrieve();

  return {
    healthy:
      typeof searchResponse === "string" && JSON.parse(searchResponse).ok,
  };
}