Fix API calls to hit emulated Firebase (#424)
This commit is contained in:
parent
33ddd86add
commit
069b88d6fd
|
@ -1,7 +1,7 @@
|
|||
import { NextApiRequest, NextApiResponse } from 'next'
|
||||
import { FIREBASE_CONFIG } from 'common/envs/constants'
|
||||
import { promisify } from 'util'
|
||||
import { pipeline } from 'stream'
|
||||
import { getFunctionUrl } from 'web/lib/firebase/api-call'
|
||||
import fetch, { Headers, Response } from 'node-fetch'
|
||||
|
||||
function getProxiedRequestHeaders(req: NextApiRequest, whitelist: string[]) {
|
||||
|
@ -33,8 +33,7 @@ function getProxiedResponseHeaders(res: Response, whitelist: string[]) {
|
|||
}
|
||||
|
||||
export const fetchBackend = (req: NextApiRequest, endpoint: string) => {
|
||||
const { projectId, region } = FIREBASE_CONFIG
|
||||
const url = `https://${region}-${projectId}.cloudfunctions.net/${endpoint}`
|
||||
const url = getFunctionUrl(endpoint)
|
||||
const headers = getProxiedRequestHeaders(req, [
|
||||
'Authorization',
|
||||
'Content-Length',
|
||||
|
|
|
@ -38,9 +38,11 @@ export async function call(url: string, method: string, params: any) {
|
|||
// app just hit the cloud functions directly -- there's no difference and it's
|
||||
// one less hop
|
||||
|
||||
function getFunctionUrl(name: string) {
|
||||
export function getFunctionUrl(name: string) {
|
||||
const { projectId, region } = FIREBASE_CONFIG
|
||||
return `https://${region}-${projectId}.cloudfunctions.net/${name}`
|
||||
return process.env.NEXT_PUBLIC_FIREBASE_EMULATE
|
||||
? `http://localhost:5001/${projectId}/${region}/${name}`
|
||||
: `https://${region}-${projectId}.cloudfunctions.net/${name}`
|
||||
}
|
||||
|
||||
export function createContract(params: any) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user