Skip to content
This repository was archived by the owner on Oct 9, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/FunctionsClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ export class FunctionsClient {
if (!region) {
region = this.region
}
// Add region as query parameter using URL API
const url = new URL(`${this.url}/${functionName}`)
if (region && region !== 'any') {
_headers['x-region'] = region
url.searchParams.set('forceFunctionRegion', region)
}
let body: any
if (
Expand Down Expand Up @@ -88,7 +91,7 @@ export class FunctionsClient {
}
}

const response = await this.fetch(`${this.url}/${functionName}`, {
const response = await this.fetch(url.toString(), {
method: method || 'POST',
// headers priority is (high to low):
// 1. invoke-level headers
Expand Down
25 changes: 12 additions & 13 deletions test/spec/params.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,25 +166,24 @@ describe('params reached to function', () => {
})

log('assert no error')
const expected = {
url: 'http://localhost:8000/mirror',
method: 'POST',
headers: data?.headers ?? [],
body: '',
}
expect(data).toEqual(expected)
expect(error).toBeNull()

// Check that x-region header is present
expect(
(data?.headers as [Array<string>]).filter(([k, v]) => k === 'x-region' && v === validRegion)
.length > 0
).toBe(true)

// Check that the URL contains the forceFunctionRegion query parameter
expect(data?.url).toContain(`forceFunctionRegion=${validRegion}`)

attach(
'check headers from function',
`expected to include: ${['custom-header', customHeader]}\n actual: ${JSON.stringify(
data?.headers
)}`,
ContentType.TEXT
)
console.log(data?.headers)
expect(
(data?.headers as [Array<string>]).filter(([k, v]) => k === 'x-region' && v === validRegion)
.length > 0
).toBe(true)
})

test('invoke with region overrides region in the client', async () => {
Expand All @@ -210,7 +209,7 @@ describe('params reached to function', () => {

log('assert no error')
const expected = {
url: 'http://localhost:8000/mirror',
url: `http://localhost:8000/mirror?forceFunctionRegion=${FunctionRegion.ApSoutheast1}`,
method: 'POST',
headers: data?.headers ?? [],
body: '',
Expand Down