changed deployment
This commit is contained in:
parent
ea4e057b02
commit
70396c321a
22 changed files with 391 additions and 52 deletions
|
|
@ -7,14 +7,12 @@ describe('API client', () => {
|
|||
sessionStorage.clear()
|
||||
})
|
||||
|
||||
it('derives the local tenant API origin from the browser hostname', () => {
|
||||
it('uses the same-origin API behind the local HTTPS proxy', () => {
|
||||
expect(tenantFromHostname('nmbs.guess.local')).toBe('nmbs')
|
||||
expect(tenantFromHostname('ypto.guess.local')).toBe('ypto')
|
||||
expect(tenantFromHostname('localhost')).toBeNull()
|
||||
expect(tenantFromHostname('127.0.0.1')).toBeNull()
|
||||
expect(apiBaseURL({ hostname: 'nmbs.guess.local', protocol: 'http:' })).toBe(
|
||||
'http://nmbs.guess.local:8080/api',
|
||||
)
|
||||
expect(apiBaseURL({ hostname: 'nmbs.guess.local', protocol: 'https:' })).toBe('/api')
|
||||
expect(apiBaseURL({ hostname: 'app.example.com', protocol: 'https:' })).toBe('/api')
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ export function tenantFromHostname(hostname: string): string | null {
|
|||
export function apiBaseURL(location: Pick<Location, 'hostname' | 'protocol'>): string {
|
||||
const hostname = location.hostname.toLowerCase().replace(/\.$/, '')
|
||||
if (hostname.endsWith('.guess.local')) {
|
||||
return `${location.protocol}//${hostname}:8080/api`
|
||||
return '/api'
|
||||
}
|
||||
return '/api'
|
||||
}
|
||||
|
|
@ -93,7 +93,11 @@ function apiURL(path: string): string {
|
|||
|
||||
function tenantHeader(): Record<string, string> {
|
||||
const tenant = tenantFromHostname(window.location.hostname)
|
||||
return tenant ? { 'X-Tenant-Id': tenant } : {}
|
||||
const apiKey = import.meta.env.VITE_GO_LOOSE_API_KEY
|
||||
return {
|
||||
...(tenant ? { 'X-Tenant-Id': tenant } : {}),
|
||||
...(typeof apiKey === 'string' && apiKey !== '' ? { 'X-API-Key': apiKey } : {}),
|
||||
}
|
||||
}
|
||||
|
||||
async function request<T>(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue