Skip to content

Commit 51124fd

Browse files
committed
feat: add @algolia/requester-fetch dependency and update Algolia integration
1 parent 59af235 commit 51124fd

File tree

5 files changed

+541
-516
lines changed

5 files changed

+541
-516
lines changed

bun.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"": {
55
"name": "api",
66
"dependencies": {
7+
"@algolia/requester-fetch": "^5.25.0",
78
"@cloudflare/workers-types": "^4.20250414.0",
89
"@hono/zod-validator": "^0.4.3",
910
"@prisma/adapter-d1": "^6.6.0",
@@ -33,6 +34,10 @@
3334
},
3435
},
3536
"packages": {
37+
"@algolia/client-common": ["@algolia/client-common@5.25.0", "", {}, "sha512-il1zS/+Rc6la6RaCdSZ2YbJnkQC6W1wiBO8+SH+DE6CPMWBU6iDVzH0sCKSAtMWl9WBxoN6MhNjGBnCv9Yy2bA=="],
38+
39+
"@algolia/requester-fetch": ["@algolia/requester-fetch@5.25.0", "", { "dependencies": { "@algolia/client-common": "5.25.0" } }, "sha512-rtzXwqzFi1edkOF6sXxq+HhmRKDy7tz84u0o5t1fXwz0cwx+cjpmxu/6OQKTdOJFS92JUYHsG51Iunie7xbqfQ=="],
40+
3641
"@babel/runtime": ["@babel/runtime@7.27.0", "", { "dependencies": { "regenerator-runtime": "^0.14.0" } }, "sha512-VtPOkrdPHZsKc/clNqyi9WUA8TINkZ4cGk63UUE3u4pmB2k+ZMQRDuIOagv8UVd6j7k0T3+RRIb7beKTebNbcw=="],
3742

3843
"@cloudflare/kv-asset-handler": ["@cloudflare/kv-asset-handler@0.4.0", "", { "dependencies": { "mime": "^3.0.0" } }, "sha512-+tv3z+SPp+gqTIcImN9o0hqE9xyfQjI1XD9pL6NuKjua9B1y7mNYv0S9cP+QEbA4ppVgGZEmKOvHX5G5Ei1CVA=="],

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"build": "tsc"
1616
},
1717
"dependencies": {
18+
"@algolia/requester-fetch": "^5.25.0",
1819
"@cloudflare/workers-types": "^4.20250414.0",
1920
"@hono/zod-validator": "^0.4.3",
2021
"@prisma/adapter-d1": "^6.6.0",

src/config/algolia.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
import algoliasearch from "algoliasearch";
22
import type { Context } from "hono";
33
import { env } from "hono/adapter";
4+
import { createFetchRequester } from "@algolia/requester-fetch";
45

56
const algolia = (c: Context) => {
6-
const { ALGOLIA_APP_ID, ALGOLIA_API_KEY } = env<{
7-
ALGOLIA_APP_ID: string;
8-
ALGOLIA_API_KEY: string;
9-
}>(c);
7+
const { ALGOLIA_APP_ID, ALGOLIA_API_KEY } = env<{
8+
ALGOLIA_APP_ID: string;
9+
ALGOLIA_API_KEY: string;
10+
}>(c);
1011

11-
return algoliaWithEnv(ALGOLIA_APP_ID, ALGOLIA_API_KEY);
12+
return algoliaWithEnv(ALGOLIA_APP_ID, ALGOLIA_API_KEY);
1213
}
1314

1415
export const algoliaWithEnv = (appId: string, apiKey: string) => {
15-
const client = algoliasearch(appId, apiKey);
16-
const index = client.initIndex("nthu_courses");
17-
return index;
18-
}
16+
const client = algoliasearch(appId, apiKey, { requester: createFetchRequester() });
17+
const index = client.initIndex("nthu_courses");
18+
return index;
19+
};
1920

2021
export default algolia;

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,4 @@ const APIHandler = {
6363

6464
};
6565

66-
export default APIHandler;
66+
export default APIHandler;

0 commit comments

Comments
 (0)