aboutsummaryrefslogtreecommitdiff
path: root/routes/api
diff options
context:
space:
mode:
Diffstat (limited to 'routes/api')
-rw-r--r--routes/api/npm.ts30
-rw-r--r--routes/api/npmregistry.ts9
2 files changed, 39 insertions, 0 deletions
diff --git a/routes/api/npm.ts b/routes/api/npm.ts
new file mode 100644
index 0000000..4063fc7
--- /dev/null
+++ b/routes/api/npm.ts
@@ -0,0 +1,30 @@
+import { Handlers } from "$fresh/server.ts";
+
+export const handler: Handlers<any, { data: any }> = {
+ async POST(_req, ctx) {
+ const requestPackages: Object = await _req.json();
+ // Loop through items
+ console.log(typeof requestPackages)
+ let packageUrls: any[] = [];
+ for (let packageName in requestPackages) {
+ packageUrls = [
+ ...packageUrls,
+ `https://registry.npmjs.org/${packageName}`
+ ];
+ }
+
+ const packageDetailsResponse = await fetchPackageDetails(packageUrls);
+ const packageDetails = Object.keys(requestPackages).map((packageName, index) => {
+ return {
+ [packageName]: packageDetailsResponse[index]
+ }
+ })
+ return Response.json({ packageDetails });
+ },
+};
+
+async function fetchPackageDetails(packageUrls: any[]) {
+ return await Promise.all(
+ packageUrls.map(url => fetch(url).then(res => res.json()))
+ )
+}
diff --git a/routes/api/npmregistry.ts b/routes/api/npmregistry.ts
new file mode 100644
index 0000000..366e3bf
--- /dev/null
+++ b/routes/api/npmregistry.ts
@@ -0,0 +1,9 @@
+import { Handlers } from "$fresh/server.ts";
+
+export const handler: Handlers<any, { data: string }> = {
+ async GET(_req, ctx) {
+ const registryResponse = await fetch('https://registry.npmjs.org/@angular/core');
+ const data = await registryResponse.json();
+ return Response.json({data});
+ },
+};