-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
31 lines (29 loc) · 1.18 KB
/
main.ts
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
31
import { serve } from "https://deno.land/[email protected]/http/server.ts";
import { fetchItems, getAllProducts, getReleaseNoteVersion, getUniqueUrl, Product } from "./lib.ts";
await serve(async (req) => {
const items = await fetchItems();
const allProducts = getAllProducts(items);
const targetUrl = new URL(req.url).searchParams.get("url");
if (targetUrl) {
const targetSearchUrl = getUniqueUrl(targetUrl);
const targetProduct = allProducts.find((product) => targetSearchUrl === product.url);
if (!targetProduct) {
return new Response("Not Found this product", {
status: 404,
});
}
const targetReleaseNoteVersion = getReleaseNoteVersion(targetUrl);
const resultProduct: Product = {
...targetProduct,
releaseNoteVersion: targetReleaseNoteVersion,
};
return new Response(JSON.stringify(resultProduct), {
headers: { "content-type": "application/json" },
});
} else {
return new Response(JSON.stringify(allProducts), {
headers: { "content-type": "application/json" },
});
}
});
console.log("http://localhost:8000");