Files
AstralRinth/apps/frontend/src/server/utils/api-client.ts
T
Calum H. 986a7e6216 feat: ssr fixes + switch project page to tanstack (#5192)
* feat: ssr fixes

* feat: lazy load non-core data

* feat: ssr timing debugging

* feat: go back to all parallel

* feat: migrate to DI + set up mutators

* feat: remove double get versions request, only call v3

* refactor: [version].vue page to use composition API and typescript

* feat: gallery.vue start

* fix: remove left behind console log

* fix: type issues + gallery

* fix: versionsummary modal + version page direct join

* fix: projectRaw guard

* fix: currentMember val fix

* fix: actualProjectType

* fix: vers summary link same page

* fix: lint

---------

Co-authored-by: tdgao <mr.trumgao@gmail.com>
2026-01-23 12:12:50 -08:00

48 lines
1.1 KiB
TypeScript

import {
type AuthConfig,
AuthFeature,
type FeatureConfig,
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 interface ServerModrinthClientOptions {
event?: H3Event
authToken?: string
}
export function useServerModrinthClient(options?: ServerModrinthClientOptions): NuxtModrinthClient {
const config = useRuntimeConfig(options?.event)
const apiBaseUrl = (config.apiBaseUrl || config.public.apiBaseUrl).replace('/v2/', '/')
const features = []
if (options?.authToken) {
features.push(
new AuthFeature({
token: options.authToken,
tokenPrefix: '',
} as AuthConfig as FeatureConfig),
)
}
const clientConfig: NuxtClientConfig = {
labrinthBaseUrl: apiBaseUrl,
rateLimitKey: config.rateLimitKey || getRateLimitKeyFromSecretsStore,
features,
}
return new NuxtModrinthClient(clientConfig)
}