forked from didirus/AstralRinth
* feat: switch to api-client to prevent rate limit errors on game-versions * feat: sentry temp * Revert "feat: sentry temp" This reverts commit aaa21a3f8099b86fa8e8d9d64845273e66c28bbe.
26 lines
797 B
TypeScript
26 lines
797 B
TypeScript
import { type NuxtClientConfig, NuxtModrinthClient } from '@modrinth/api-client'
|
|
import type { H3Event } from 'h3'
|
|
|
|
async function getRateLimitKeyFromSecretsStore(): Promise<string | undefined> {
|
|
try {
|
|
const mod = 'cloudflare:workers'
|
|
const { env } = await import(/* @vite-ignore */ mod)
|
|
return await env.RATE_LIMIT_IGNORE_KEY?.get()
|
|
} catch {
|
|
return undefined
|
|
}
|
|
}
|
|
|
|
export function useServerModrinthClient(event: H3Event): NuxtModrinthClient {
|
|
const config = useRuntimeConfig(event)
|
|
const apiBaseUrl = (config.apiBaseUrl || config.public.apiBaseUrl).replace('/v2/', '/')
|
|
|
|
const clientConfig: NuxtClientConfig = {
|
|
labrinthBaseUrl: apiBaseUrl,
|
|
rateLimitKey: config.rateLimitKey || getRateLimitKeyFromSecretsStore,
|
|
features: [],
|
|
}
|
|
|
|
return new NuxtModrinthClient(clientConfig)
|
|
}
|