@@ -3,12 +3,14 @@ import "dotenv/config";
33import express , { Application , Request , Response } from "express" ;
44import axios from "axios" ;
55import { env } from "process" ;
6+ import cors from "cors" ;
67
78// Env setup
89const apiKey = env [ "apiKey" ] ;
910
1011// Express server
1112const app : Application = express ( ) ;
13+ app . use ( cors ( ) ) ;
1214const port = 3001 ;
1315
1416// Axios setup
@@ -20,11 +22,14 @@ app.use(express.urlencoded({ extended: true }));
2022app . use ( express . static ( __dirname + "/../public" ) ) ;
2123
2224type NFT = {
25+ contract : string ;
2326 img : string ;
2427 id : number ;
2528} ;
2629
27- type NFTs = { [ contract : string ] : NFT [ ] } ;
30+ type NFTs = NFT [ ] ;
31+
32+ type NFTsByCollection = { [ collectionName : string ] : NFTs } ;
2833
2934type Collection = {
3035 name : string ;
@@ -57,7 +62,7 @@ app.get("/drop/:drop/:address", async (req: Request, res: Response): Promise<Res
5762 const drop = DROPS [ req . params . drop as any as number ] ;
5863 const address = req . params . address ;
5964
60- let nftsForDropByAddress : NFTs = { } ;
65+ let nftsForDropByAddress : NFTsByCollection = { } ;
6166
6267 for ( let collection of drop . collections ) {
6368 const resq = await axios . get (
@@ -67,12 +72,13 @@ app.get("/drop/:drop/:address", async (req: Request, res: Response): Promise<Res
6772 let nfts : NFT [ ] = [ ] ;
6873 for ( let asset of resq . data . assets ) {
6974 nfts . push ( {
75+ contract : collection . contract ,
7076 img : asset . image_url ,
7177 id : asset . token_id ,
7278 } ) ;
7379 }
7480
75- nftsForDropByAddress [ collection . contract ] = nfts ;
81+ nftsForDropByAddress [ collection . name ] = nfts ;
7682 }
7783
7884 return res . status ( 200 ) . send ( nftsForDropByAddress ) ;
0 commit comments