Skip to content

Commit

Permalink
feat: support passing headers to hub proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
RihanArfan committed Oct 26, 2024
1 parent 3077181 commit 50cee14
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 14 deletions.
5 changes: 3 additions & 2 deletions src/runtime/ai/server/utils/ai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,15 @@ export function hubAI(): Ai {
*
* @see https://developers.cloudflare.com/workers-ai/configuration/bindings/#methods
*/
export function proxyHubAI(projectUrl: string, secretKey?: string): Ai {
export function proxyHubAI(projectUrl: string, secretKey?: string, headers?: HeadersInit): Ai {
requireNuxtHubFeature('ai')

const aiAPI = ofetch.create({
baseURL: joinURL(projectUrl, '/api/_hub/ai'),
method: 'POST',
headers: {
Authorization: `Bearer ${secretKey}`
Authorization: `Bearer ${secretKey}`,
...headers
}
})
return {
Expand Down
5 changes: 3 additions & 2 deletions src/runtime/analytics/server/utils/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ export function hubAnalytics() {
}
}

export function proxyHubAnalytics(projectUrl: string, secretKey?: string) {
export function proxyHubAnalytics(projectUrl: string, secretKey?: string, headers?: HeadersInit) {
requireNuxtHubFeature('analytics')

const analyticsAPI = ofetch.create({
baseURL: joinURL(projectUrl, '/api/_hub/analytics'),
headers: {
Authorization: `Bearer ${secretKey}`
Authorization: `Bearer ${secretKey}`,
...headers
}
})

Expand Down
5 changes: 3 additions & 2 deletions src/runtime/blob/server/utils/blob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,13 +328,14 @@ export function hubBlob(): HubBlob {
*
* @see https://hub.nuxt.com/docs/features/blob
*/
export function proxyHubBlob(projectUrl: string, secretKey?: string): HubBlob {
export function proxyHubBlob(projectUrl: string, secretKey?: string, headers?: HeadersInit): HubBlob {
requireNuxtHubFeature('blob')

const blobAPI = ofetch.create({
baseURL: joinURL(projectUrl, '/api/_hub/blob'),
headers: {
Authorization: `Bearer ${secretKey}`
Authorization: `Bearer ${secretKey}`,
...headers
}
})

Expand Down
5 changes: 3 additions & 2 deletions src/runtime/cache/server/utils/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ import { requireNuxtHubFeature } from '../../../utils/features'
* ```
*
*/
export function proxyHubCache(projectUrl: string, secretKey?: string) {
export function proxyHubCache(projectUrl: string, secretKey?: string, headers?: HeadersInit) {
requireNuxtHubFeature('cache')

const cacheAPI = ofetch.create({
baseURL: joinURL(projectUrl, '/api/_hub/cache'),
headers: {
Authorization: `Bearer ${secretKey}`
Authorization: `Bearer ${secretKey}`,
...headers
}
})

Expand Down
5 changes: 3 additions & 2 deletions src/runtime/database/server/utils/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,15 @@ export function hubDatabase(): D1Database {
*
* @see https://hub.nuxt.com/docs/features/database
*/
export function proxyHubDatabase(projectUrl: string, secretKey?: string): D1Database {
export function proxyHubDatabase(projectUrl: string, secretKey?: string, headers?: HeadersInit): D1Database {
requireNuxtHubFeature('database')

const d1API = ofetch.create({
baseURL: joinURL(projectUrl, '/api/_hub/database'),
method: 'POST',
headers: {
Authorization: `Bearer ${secretKey}`
Authorization: `Bearer ${secretKey}`,
...headers
}
})
return {
Expand Down
5 changes: 3 additions & 2 deletions src/runtime/kv/server/utils/kv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,15 @@ export function hubKV(): HubKV {
*
* @see https://hub.nuxt.com/docs/features/kv
*/
export function proxyHubKV(projectUrl: string, secretKey?: string): HubKV {
export function proxyHubKV(projectUrl: string, secretKey?: string, headers?: HeadersInit): HubKV {
requireNuxtHubFeature('kv')

const storage = createStorage({
driver: httpDriver({
base: joinURL(projectUrl, '/api/_hub/kv/'),
headers: {
Authorization: `Bearer ${secretKey}`
Authorization: `Bearer ${secretKey}`,
...headers
}
})
})
Expand Down
5 changes: 3 additions & 2 deletions src/runtime/vectorize/server/utils/vectorize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,15 @@ export function hubVectorize(index: VectorizeIndexes): Vectorize {
*
* @see https://developers.cloudflare.com/vectorize/reference/client-api/
*/
export function proxyHubVectorize(index: VectorizeIndexes, projectUrl: string, secretKey?: string): Vectorize {
export function proxyHubVectorize(index: VectorizeIndexes, projectUrl: string, secretKey?: string, headers?: HeadersInit): Vectorize {
requireNuxtHubFeature('vectorize')

const vectorizeAPI = ofetch.create({
baseURL: joinURL(projectUrl, `/api/_hub/vectorize/${index}`),
method: 'POST',
headers: {
Authorization: `Bearer ${secretKey}`
Authorization: `Bearer ${secretKey}`,
...headers
}
})
return {
Expand Down

0 comments on commit 50cee14

Please sign in to comment.