File tree Expand file tree Collapse file tree 3 files changed +32
-0
lines changed
Expand file tree Collapse file tree 3 files changed +32
-0
lines changed Original file line number Diff line number Diff line change 1+ const NPM_API = `https://api.npmjs.org/downloads/point/last-month`
2+
3+ export async function getNpmPackage ( packageName : string ) {
4+ return fetch ( `${ NPM_API } /${ packageName } ` , {
5+ cache : 'no-store' ,
6+ } )
7+ }
Original file line number Diff line number Diff line change 1+ import { getNpmPackage } from './npm'
2+ import type { NextRequest } from 'next/server'
3+
4+ export async function GET ( request : NextRequest ) {
5+ const params = new URL ( request . url ) . searchParams
6+ const packageName = params . get ( 'package' )
7+ if ( ! packageName ) {
8+ return Response . json ( { message : 'Missing package parameter' } , { status : 400 } )
9+ }
10+ const response = await getNpmPackage ( packageName )
11+ if ( response . status === 204 || response . status > 400 ) {
12+ return Response . json ( { message : 'Package not found' } , { status : 404 } )
13+ }
14+
15+ const data = await response . json ( )
16+
17+ return Response . json ( data )
18+ }
Original file line number Diff line number Diff line change @@ -122,6 +122,13 @@ export type GithubRepository = {
122122 repositoryTopics : string [ ]
123123}
124124
125+ export type NpmPackage = {
126+ downloads : number
127+ start : string
128+ end : string
129+ package : string
130+ }
131+
125132export type ImdbFriends = {
126133 type : string
127134 name : string
You can’t perform that action at this time.
0 commit comments