Initial Commit
* Implements Basic Routing and API * Implements Package.json file select and json parse * Displays Project Name, Version & Desc from the package.json * Fetch all package details using npm registry API and map it based on package name
This commit is contained in:
30
routes/api/npm.ts
Normal file
30
routes/api/npm.ts
Normal file
@@ -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()))
|
||||
)
|
||||
}
|
||||
9
routes/api/npmregistry.ts
Normal file
9
routes/api/npmregistry.ts
Normal file
@@ -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});
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user