Worker migration (#5072)

* Worker migration

* Deploy on pnpm changes

* Specify package manager

* Manually bump Wrangler to 4.54

* Get rid of useless Wranglers worker

* I take it back

* Set account ID

* Fix preview alias

* feat: use workers api key

* feat: try fix

* fix: missing imports

* fix: again

* fix: only run push workflow on main or prod

* feat: remove store id?

* Populate secret store IDs

* Use correct key name

* Fix setting PREVIEW variable

* Inject variables from wrangler into shell

* Inject variables from wrangler into shell

* Add git- prefix to preview-alias

* No need to use environments now

* fix: remove test as it's covered by staging deploy

---------

Co-authored-by: Michael H. <michael@iptables.sh>
This commit is contained in:
Calum H.
2026-01-08 11:25:45 -05:00
committed by GitHub
parent 8175120c4c
commit 62e56eb27e
9 changed files with 739 additions and 47 deletions

View File

@@ -43,10 +43,11 @@ export class NuxtCircuitBreakerStorage implements CircuitBreakerStorage {
export interface NuxtClientConfig extends ClientConfig {
// TODO: do we want to provide this for tauri+base as well? its not used on app
/**
* Rate limit key for server-side requests
* This is injected as x-ratelimit-key header on server-side
* Rate limit key for server-side requests.
* This is injected as x-ratelimit-key header on server-side.
* Can be a string (for env var) or async function (for CF Secrets Store).
*/
rateLimitKey?: string
rateLimitKey?: string | (() => Promise<string | undefined>)
}
/**
@@ -75,6 +76,8 @@ export interface NuxtClientConfig extends ClientConfig {
*/
export class NuxtModrinthClient extends XHRUploadClient {
declare protected config: NuxtClientConfig
private rateLimitKeyResolved: string | undefined
private rateLimitKeyPromise: Promise<string | undefined> | undefined
constructor(config: NuxtClientConfig) {
super(config)
@@ -87,6 +90,40 @@ export class NuxtModrinthClient extends XHRUploadClient {
})
}
/**
* Resolve the rate limit key, handling both string and async function values.
* Results are cached for subsequent calls.
*/
private async resolveRateLimitKey(): Promise<string | undefined> {
if (this.rateLimitKeyResolved !== undefined) {
return this.rateLimitKeyResolved
}
const key = this.config.rateLimitKey
if (typeof key === 'string') {
this.rateLimitKeyResolved = key
} else if (typeof key === 'function') {
if (!this.rateLimitKeyPromise) {
this.rateLimitKeyPromise = key()
}
this.rateLimitKeyResolved = await this.rateLimitKeyPromise
}
return this.rateLimitKeyResolved
}
/**
* Override request to resolve rate limit key before calling super.
* This allows async fetching of the key from CF Secrets Store.
*/
async request<T>(path: string, options: RequestOptions): Promise<T> {
// @ts-expect-error - import.meta is provided by Nuxt
if (import.meta.server) {
await this.resolveRateLimitKey()
}
return super.request(path, options)
}
/**
* Upload a file with progress tracking
*
@@ -132,9 +169,10 @@ export class NuxtModrinthClient extends XHRUploadClient {
...super.buildDefaultHeaders(),
}
// Use the resolved key (populated by resolveRateLimitKey in request())
// @ts-expect-error - import.meta is provided by Nuxt
if (import.meta.server && this.config.rateLimitKey) {
headers['x-ratelimit-key'] = this.config.rateLimitKey
if (import.meta.server && this.rateLimitKeyResolved) {
headers['x-ratelimit-key'] = this.rateLimitKeyResolved
}
return headers