Fix API response too large :)
This commit is contained in:
26
frontend/server/api/champions.ts
Normal file
26
frontend/server/api/champions.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { MongoClient } from 'mongodb';
|
||||
import {connectToDatabase, fetchLatestPatch} from '../utils/mongo'
|
||||
|
||||
async function champions(client: MongoClient, patch: string) {
|
||||
const database = client.db("champions");
|
||||
const collection = database.collection(patch);
|
||||
const data : Array<ChampionData> = (await collection.find().toArray()) as unknown as Array<ChampionData>
|
||||
data.map((x) => {
|
||||
for(let lane of x.lanes) {
|
||||
delete lane.builds
|
||||
delete lane.runes
|
||||
}
|
||||
})
|
||||
return data
|
||||
}
|
||||
|
||||
export default defineEventHandler(async (_) => {
|
||||
const client = await connectToDatabase();
|
||||
const latestPatch = await fetchLatestPatch(client);
|
||||
|
||||
const data = await champions(client, latestPatch);
|
||||
|
||||
await client.close()
|
||||
|
||||
return data
|
||||
})
|
||||
Reference in New Issue
Block a user