on master help sign in
api: amend apis, stub for staging
commit69faeb4cb70349e453965aac94c39848e8e4e16a authorMatilde Park <matilde.park@urbit.org> dateWed 19 Oct 2022, 12:24 (4 years ago) parent6d54701
4 files changed+12−13
pages/api/dev-search.js+1−1 pages/api/glossary.js−10 pages/api/ops-search.js+1−1 pages/api/search.js+10−1
pages/api/dev-search.js+1−1
@@ -1,6 +1,6 @@
11export default async (req, res) => {
22 const results = await fetch(
3− `https://developers.urbit.org/api/search?q=${req.query.q}`
3+ `https://developers-urbit-bls6d8h8w-urbit.vercel.app/api/search?q=${encodeURIComponent(req.query.q)}`
44 ).then((res) => res.json());
55 res.statusCode = 200;
66 res.setHeader("Content-Type", "application/json");
pages/api/glossary.jsdeleted−10
@@ -1,10 +0,0 @@
1−export default async (req, res) => {
2− const results = await fetch(
3− `https://developers.urbit.org/api/glossary?q=${encodeURIComponent(
4− req.query.q
5− )}`
6− ).then((res) => res.json());
7− res.statusCode = 200;
8− res.setHeader("Content-Type", "application/json");
9− res.end(JSON.stringify(results));
10−};
pages/api/ops-search.js+1−1
@@ -1,6 +1,6 @@
11export default async (req, res) => {
22 const results = await fetch(
3− `https://operators.urbit.org/api/search?q=${req.query.q}`
3+ `https://operators-urbit-kpkx6sfyq-urbit.vercel.app/api/search?q=${req.query.q}`
44 ).then((res) => res.json());
55 res.statusCode = 200;
66 res.setHeader("Content-Type", "application/json");
pages/api/search.js+10−1
@@ -1,4 +1,5 @@
11import { index } from "../../cache/data";
2+import { glossary } from "../../cache/glossary";
23const levenSort = require("leven-sort");
34
45export default (req, res) => {
@@ -9,6 +10,13 @@ export default (req, res) => {
910 e?.parent.toLowerCase().includes(req.query.q.toLowerCase())
1011 );
1112
13+ const entries = glossary.filter((entry) => {
14+ return (
15+ entry.name.includes(req.query.q.toLowerCase()) ||
16+ entry.symbol.includes(req.query.q)
17+ );
18+ });
19+
1220 results.push(
1321 ...index
1422 .filter((e) => !results.includes(e))
@@ -30,7 +38,8 @@ export default (req, res) => {
3038 "parent",
3139 "headings",
3240 ]);
41+ const sortedEntries = levenSort(entries, req.query.q, ["symbol"]);
3342 res.statusCode = 200;
3443 res.setHeader("Content-Type", "application/json");
35− res.end(JSON.stringify({ results: sorted }));
44+ res.end(JSON.stringify({ results: sorted, glossary: sortedEntries }));
3645};