Skip to content

Commit e5d150c

Browse files
committed
Avoid cache on local Gateway check
1 parent 0ce8a5c commit e5d150c

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

frontend/ts-src/services/backend.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,13 @@ export class Backend {
189189

190190
private gatewayPost = async <Body, Response>(path: string, body: Body, zod: ZodType<Response>): Promise<Response> => {
191191
const gateway_local = 'http://localhost:4177'
192-
return Http.getJson(`${gateway_local}/ping`, GatewayPing).then(_ => {
192+
const now = Date.now()
193+
return Http.getJson(`${gateway_local}/ping?time=${now}`, GatewayPing, {cache: 'no-store'}).then(_ => {
193194
return Http.postJson(`${gateway_local}/gateway${path}`, body, zod)
194195
.catch(err => Promise.reject(`Local gateway: ${errorToString(err)}`))
195196
}, _ => {
196197
const gateway_remote = window.gateway_url || ''
197-
return Http.getJson(`${gateway_remote}/ping`, GatewayPing)
198+
return Http.getJson(`${gateway_remote}/ping?time=${now}`, GatewayPing, {cache: 'no-store'})
198199
.then(_ => Http.postJson(`${gateway_remote}/gateway${path}`, body, zod))
199200
.catch(err => Promise.reject(`${gateway_remote.includes('azimutt.app') ? 'Azimutt gateway' : 'Custom gateway'}: ${errorToString(err)}, forgot to start the local gateway? (npx azimutt@latest gateway)`))
200201
})

frontend/ts-src/utils/http.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {ZodType} from "zod";
22
import {zodParse} from "@azimutt/models";
33
import * as Json from "./json";
44

5-
export const getJson = <Response>(url: string, zod: ZodType<Response>): Promise<Response> => customFetch('GET', url, undefined, zod)
5+
export const getJson = <Response>(url: string, zod: ZodType<Response>, headers?: RequestInit): Promise<Response> => customFetch('GET', url, undefined, zod, headers)
66
export const postJson = <Body, Response>(url: string, body: Body, zod: ZodType<Response>): Promise<Response> => customFetch('POST', url, body, zod)
77
export const postNoContent = <Body>(url: string, body: Body): Promise<void> => customFetch('POST', url, body)
88
export const postMultipart = <Response>(url: string, body: FormData, zod: ZodType<Response>): Promise<Response> => customFetch('POST', url, body, zod)
@@ -12,9 +12,10 @@ export const deleteNoContent = (url: string): Promise<void> => customFetch('DELE
1212

1313
type Method = 'GET' | 'POST' | 'PUT' | 'DELETE'
1414

15-
function customFetch<Body, Response>(method: Method, path: string, body?: Body, zod?: ZodType<Response>): Promise<Response> {
15+
function customFetch<Body, Response>(method: Method, path: string, body?: Body, zod?: ZodType<Response>, headers?: RequestInit): Promise<Response> {
1616
const url = path.startsWith('http') ? path : `${window.location.origin}${path}`
17-
let opts: RequestInit = path.startsWith('http') ? {method} : {method, credentials: 'include'}
17+
let opts: RequestInit = headers ? headers : {}
18+
opts = path.startsWith('http') ? {...opts, method} : {...opts, method, credentials: 'include'}
1819
if (body instanceof FormData) {
1920
opts = {...opts, body: body}
2021
} else if (typeof body === 'object' && body !== null) {

0 commit comments

Comments
 (0)