#Singleton API initialization not working correctly.

1 messages · Page 1 of 1 (latest)

real island
#

I have expensive API that I want to only initialize once as it makes some web calls that need to be handled. I feel like it should work, but maybe im doing it wrong?

I attached how the api gets initialized (based on prisma's way of doing it) but it will will reinit on different routes.

such as home, /search, /search/player/[...].

The main issue is that every new player page (the catchall /search/player/[...]) reinits the API EVERY single time which I can have happening. Any thoughts?

This is how I use it given the ./api.ts file attached to the post.

import { api } from "./api"

console.log(api.getHeroes())
console.log(api.searchAccount("test123"))

in a test file like this, it works wonders but breaks with the reinitializing between pages. any way to get around this issue?

sleek muralBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)