Files
supabase/apps/studio/lib/pingPostgrest.ts
Joshen Lim dbb413beeb Chore/deprecate lib common fetch 03 (#36529)
* Deprecate use of getWithTimeout, refactor BuildingState and RestoringState to use RQ

* Refactor profile-create-mutation to use data/fetchers, and edge-function-status-query to use fetch

* Shift post from lib/common/fetch, refactor bucket-object-download-mutation

* Address feedback

* Minor fix

* Refactor post calls from lib/common/fetch in auth pages to data/fetchers

* Add missing POST users endpoint + small fix when deleting user via context menu

* Remove all use of any imports from lib/common/fetch

* Clean up remaining usage of lib/common/fetch

* Fix fetchHeadWithTimeout

* simplify handleFetchError

* allow handleFetchError to accept unknown

* non-breaking change

* small fixes

* fix query path

---------

Co-authored-by: Alaister Young <a@alaisteryoung.com>
2025-07-21 16:59:17 +08:00

41 lines
999 B
TypeScript

import { fetchHeadWithTimeout } from 'data/fetchers'
import { API_URL } from './constants'
const DEFAULT_TIMEOUT_MILLISECONDS = 2000
/**
* Ping Postgrest for health check. Default timeout in 2s.
*
* @param restUrl project rest url
* @param apikey project internal api key
* @param options optional, include custom timeout in milliseconds
*
* @return true if ping is successful else false
*/
async function pingPostgrest(
projectRef: string,
options?: {
timeout?: number
}
) {
if (projectRef === undefined) return false
const { timeout } = options ?? {}
return pingOpenApi(projectRef, timeout)
}
export default pingPostgrest
/**
* Send a HEAD request to postgrest OpenAPI.
*
* @return true if there's no error else false
*/
async function pingOpenApi(ref: string, timeout?: number) {
const { error } = await fetchHeadWithTimeout(`${API_URL}/projects/${ref}/api/rest`, [], {
timeout: timeout ?? DEFAULT_TIMEOUT_MILLISECONDS,
})
return error === undefined
}