From 49859e6f0029f0a16c1e53186a047728a6a53bb6 Mon Sep 17 00:00:00 2001 From: Marshall Polaris Date: Fri, 3 Jun 2022 00:50:24 -0700 Subject: [PATCH] Call cloud functions directly from web client instead of proxy (#405) --- web/lib/firebase/api-call.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/web/lib/firebase/api-call.ts b/web/lib/firebase/api-call.ts index 3fa93004..08f26ff4 100644 --- a/web/lib/firebase/api-call.ts +++ b/web/lib/firebase/api-call.ts @@ -1,4 +1,5 @@ import { auth } from './users' +import { FIREBASE_CONFIG } from 'common/envs/constants' export class APIError extends Error { code: number @@ -32,10 +33,20 @@ export async function call(url: string, method: string, params: any) { }) } +// Our users access the API through the Vercel proxy routes at /api/v0/blah, +// but right now at least until we get performance under control let's have the +// app just hit the cloud functions directly -- there's no difference and it's +// one less hop + +function getFunctionUrl(name: string) { + const { projectId, region } = FIREBASE_CONFIG + return `https://${region}-${projectId}.cloudfunctions.net/${name}` +} + export function createContract(params: any) { - return call('/api/v0/market', 'POST', params) + return call(getFunctionUrl('createContract'), 'POST', params) } export function placeBet(params: any) { - return call('/api/v0/bets', 'POST', params) + return call(getFunctionUrl('placeBet'), 'POST', params) }