Merge pull request #7824 from supabase/fix/ping-postgres-always-use-ref-for-ref

fix: "possible fix" - always use project ref incase the project resturl is different
This commit is contained in:
Jonathan Summers-Muir authored and GitHub committed 2022-07-21 10:05:17 +08:00
commit 3f042751bf
3 files changed
+9 -8

No files matched your search

@@ -37,7 +37,7 @@ const ConnectingState: FC<Props> = ({ project }) => {
}, [project])
const testProjectConnection = async () => {
const result = await pingPostgrest(project.restUrl!, {
const result = await pingPostgrest(project.restUrl!, project.ref, {
kpsVersion: project.kpsVersion,
})
if (result) {
+6 -2
View File
@@ -1,3 +1,4 @@
import { String } from 'lodash'
import semver from 'semver'
import { headWithTimeout, getWithTimeout } from './common/fetch'
import { API_URL } from './constants'
@@ -16,12 +17,12 @@ import { API_URL } from './constants'
*/
async function pingPostgrest(
restUrl: string,
projectRef: string,
options?: {
kpsVersion?: string
timeout?: number
}
) {
const projectRef = restUrl.match(/https:\/\/(\w+)\.supabase\./)?.[1]
if (projectRef === undefined) return false
const serviceApiKey = await getServiceApiKey(projectRef, options?.timeout)
if (serviceApiKey === undefined) return false
@@ -41,7 +42,10 @@ async function pingPostgrest(
}
export default pingPostgrest
const getServiceApiKey = async (projectRef: string, timeout = DEFAULT_TIMEOUT_MILLISECONDS): Promise<string | undefined> => {
const getServiceApiKey = async (
projectRef: string,
timeout = DEFAULT_TIMEOUT_MILLISECONDS
): Promise<string | undefined> => {
const response = await getWithTimeout(`${API_URL}/props/project/${projectRef}/api`, { timeout })
if (response.error || response.autoApiService.service_api_keys.length === 0) return undefined
return response.autoApiService.serviceApiKey
+2 -5
View File
@@ -62,11 +62,8 @@ export default class ProjectStore extends PostgresMetaInterface<Project> {
}
async pingPostgrest(project: Project): Promise<'ONLINE' | 'OFFLINE' | undefined> {
if (
project.status === PROJECT_STATUS.ACTIVE_HEALTHY &&
project.restUrl
) {
const success = await pingPostgrest(project.restUrl, {
if (project.status === PROJECT_STATUS.ACTIVE_HEALTHY && project.restUrl) {
const success = await pingPostgrest(project.restUrl, project.ref, {
kpsVersion: project.kpsVersion,
})
return success ? 'ONLINE' : 'OFFLINE'