Clean up definition of v2 cloud function URLs (#562)
This commit is contained in:
parent
f0d4e9940c
commit
4f9e303daa
|
@ -12,12 +12,7 @@ export const DEV_CONFIG: EnvConfig = {
|
||||||
appId: '1:134303100058:web:27f9ea8b83347251f80323',
|
appId: '1:134303100058:web:27f9ea8b83347251f80323',
|
||||||
measurementId: 'G-YJC9E37P37',
|
measurementId: 'G-YJC9E37P37',
|
||||||
},
|
},
|
||||||
functionEndpoints: {
|
cloudRunId: 'w3txbmd3ba',
|
||||||
placebet: 'https://placebet-w3txbmd3ba-uc.a.run.app',
|
cloudRunRegion: 'uc',
|
||||||
sellshares: 'https://sellshares-w3txbmd3ba-uc.a.run.app',
|
|
||||||
sellbet: 'https://sellbet-w3txbmd3ba-uc.a.run.app',
|
|
||||||
createmarket: 'https://createmarket-w3txbmd3ba-uc.a.run.app',
|
|
||||||
creategroup: 'https://creategroup-w3txbmd3ba-uc.a.run.app',
|
|
||||||
},
|
|
||||||
amplitudeApiKey: 'fd8cbfd964b9a205b8678a39faae71b3',
|
amplitudeApiKey: 'fd8cbfd964b9a205b8678a39faae71b3',
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,13 @@
|
||||||
export type V2CloudFunction =
|
|
||||||
| 'placebet'
|
|
||||||
| 'sellbet'
|
|
||||||
| 'sellshares'
|
|
||||||
| 'createmarket'
|
|
||||||
| 'creategroup'
|
|
||||||
|
|
||||||
export type EnvConfig = {
|
export type EnvConfig = {
|
||||||
domain: string
|
domain: string
|
||||||
firebaseConfig: FirebaseConfig
|
firebaseConfig: FirebaseConfig
|
||||||
functionEndpoints: Record<V2CloudFunction, string>
|
|
||||||
amplitudeApiKey?: string
|
amplitudeApiKey?: string
|
||||||
|
|
||||||
|
// IDs for v2 cloud functions -- find these by deploying a cloud function and
|
||||||
|
// examining the URL, https://[name]-[cloudRunId]-[cloudRunRegion].a.run.app
|
||||||
|
cloudRunId: string
|
||||||
|
cloudRunRegion: string
|
||||||
|
|
||||||
// Access controls
|
// Access controls
|
||||||
adminEmails: string[]
|
adminEmails: string[]
|
||||||
whitelistEmail?: string // e.g. '@theoremone.co'. If not provided, all emails are whitelisted
|
whitelistEmail?: string // e.g. '@theoremone.co'. If not provided, all emails are whitelisted
|
||||||
|
@ -48,13 +45,8 @@ export const PROD_CONFIG: EnvConfig = {
|
||||||
appId: '1:128925704902:web:f61f86944d8ffa2a642dc7',
|
appId: '1:128925704902:web:f61f86944d8ffa2a642dc7',
|
||||||
measurementId: 'G-SSFK1Q138D',
|
measurementId: 'G-SSFK1Q138D',
|
||||||
},
|
},
|
||||||
functionEndpoints: {
|
cloudRunId: 'nggbo3neva',
|
||||||
placebet: 'https://placebet-nggbo3neva-uc.a.run.app',
|
cloudRunRegion: 'uc',
|
||||||
sellshares: 'https://sellshares-nggbo3neva-uc.a.run.app',
|
|
||||||
sellbet: 'https://sellbet-nggbo3neva-uc.a.run.app',
|
|
||||||
createmarket: 'https://createmarket-nggbo3neva-uc.a.run.app',
|
|
||||||
creategroup: 'https://creategroup-nggbo3neva-uc.a.run.app',
|
|
||||||
},
|
|
||||||
adminEmails: [
|
adminEmails: [
|
||||||
'akrolsmir@gmail.com', // Austin
|
'akrolsmir@gmail.com', // Austin
|
||||||
'jahooma@gmail.com', // James
|
'jahooma@gmail.com', // James
|
||||||
|
|
|
@ -12,14 +12,8 @@ export const THEOREMONE_CONFIG: EnvConfig = {
|
||||||
appId: '1:698012149198:web:b342af75662831aa84b79f',
|
appId: '1:698012149198:web:b342af75662831aa84b79f',
|
||||||
measurementId: 'G-Y3EZ1WNT6E',
|
measurementId: 'G-Y3EZ1WNT6E',
|
||||||
},
|
},
|
||||||
// TODO: fill in real endpoints for T1
|
cloudRunId: 'nggbo3neva', // TODO: fill in real ID for T1
|
||||||
functionEndpoints: {
|
cloudRunRegion: 'uc',
|
||||||
placebet: 'https://placebet-nggbo3neva-uc.a.run.app',
|
|
||||||
sellshares: 'https://sellshares-nggbo3neva-uc.a.run.app',
|
|
||||||
sellbet: 'https://sellbet-nggbo3neva-uc.a.run.app',
|
|
||||||
createmarket: 'https://createmarket-nggbo3neva-uc.a.run.app',
|
|
||||||
creategroup: 'https://creategroup-nggbo3neva-uc.a.run.app',
|
|
||||||
},
|
|
||||||
adminEmails: [...PROD_CONFIG.adminEmails, 'david.glidden@theoremone.co'],
|
adminEmails: [...PROD_CONFIG.adminEmails, 'david.glidden@theoremone.co'],
|
||||||
whitelistEmail: '@theoremone.co',
|
whitelistEmail: '@theoremone.co',
|
||||||
moneyMoniker: 'T$',
|
moneyMoniker: 'T$',
|
||||||
|
|
|
@ -2,7 +2,6 @@ import { NextApiRequest, NextApiResponse } from 'next'
|
||||||
import { promisify } from 'util'
|
import { promisify } from 'util'
|
||||||
import { pipeline } from 'stream'
|
import { pipeline } from 'stream'
|
||||||
import { getFunctionUrl } from 'web/lib/firebase/api-call'
|
import { getFunctionUrl } from 'web/lib/firebase/api-call'
|
||||||
import { V2CloudFunction } from 'common/envs/prod'
|
|
||||||
import fetch, { Headers, Response } from 'node-fetch'
|
import fetch, { Headers, Response } from 'node-fetch'
|
||||||
|
|
||||||
function getProxiedRequestHeaders(req: NextApiRequest, whitelist: string[]) {
|
function getProxiedRequestHeaders(req: NextApiRequest, whitelist: string[]) {
|
||||||
|
@ -33,7 +32,7 @@ function getProxiedResponseHeaders(res: Response, whitelist: string[]) {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
export const fetchBackend = (req: NextApiRequest, name: V2CloudFunction) => {
|
export const fetchBackend = (req: NextApiRequest, name: string) => {
|
||||||
const url = getFunctionUrl(name)
|
const url = getFunctionUrl(name)
|
||||||
const headers = getProxiedRequestHeaders(req, [
|
const headers = getProxiedRequestHeaders(req, [
|
||||||
'Authorization',
|
'Authorization',
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { auth } from './users'
|
import { auth } from './users'
|
||||||
import { ENV_CONFIG } from 'common/envs/constants'
|
import { ENV_CONFIG } from 'common/envs/constants'
|
||||||
import { V2CloudFunction } from 'common/envs/prod'
|
|
||||||
|
|
||||||
export class APIError extends Error {
|
export class APIError extends Error {
|
||||||
code: number
|
code: number
|
||||||
|
@ -41,8 +40,9 @@ export async function call(url: string, method: string, params: any) {
|
||||||
// app just hit the cloud functions directly -- there's no difference and it's
|
// app just hit the cloud functions directly -- there's no difference and it's
|
||||||
// one less hop
|
// one less hop
|
||||||
|
|
||||||
export function getFunctionUrl(name: V2CloudFunction) {
|
export function getFunctionUrl(name: string) {
|
||||||
return ENV_CONFIG.functionEndpoints[name]
|
const { cloudRunId, cloudRunRegion } = ENV_CONFIG
|
||||||
|
return `https://${name}-${cloudRunId}-${cloudRunRegion}.a.run.app`
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createMarket(params: any) {
|
export function createMarket(params: any) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user