2022-05-21 02:34:26 +00:00
|
|
|
import { escapeRegExp } from 'lodash'
|
2022-03-09 02:43:30 +00:00
|
|
|
import { DEV_CONFIG } from './dev'
|
|
|
|
import { EnvConfig, PROD_CONFIG } from './prod'
|
|
|
|
import { THEOREMONE_CONFIG } from './theoremone'
|
|
|
|
|
2022-05-09 17:38:33 +00:00
|
|
|
export const ENV = process.env.NEXT_PUBLIC_FIREBASE_ENV ?? 'PROD'
|
2022-03-09 02:43:30 +00:00
|
|
|
|
2022-05-26 00:12:36 +00:00
|
|
|
const CONFIGS: { [env: string]: EnvConfig } = {
|
2022-03-09 02:43:30 +00:00
|
|
|
PROD: PROD_CONFIG,
|
|
|
|
DEV: DEV_CONFIG,
|
|
|
|
THEOREMONE: THEOREMONE_CONFIG,
|
|
|
|
}
|
2022-05-26 00:12:36 +00:00
|
|
|
|
|
|
|
export const ENV_CONFIG = CONFIGS[ENV]
|
2022-03-09 02:43:30 +00:00
|
|
|
|
|
|
|
export function isWhitelisted(email?: string) {
|
|
|
|
if (!ENV_CONFIG.whitelistEmail) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return email && (email.endsWith(ENV_CONFIG.whitelistEmail) || isAdmin(email))
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Before open sourcing, we should turn these into env vars
|
|
|
|
export function isAdmin(email: string) {
|
|
|
|
return ENV_CONFIG.adminEmails.includes(email)
|
|
|
|
}
|
|
|
|
|
|
|
|
export const DOMAIN = ENV_CONFIG.domain
|
|
|
|
export const FIREBASE_CONFIG = ENV_CONFIG.firebaseConfig
|
|
|
|
export const PROJECT_ID = ENV_CONFIG.firebaseConfig.projectId
|
|
|
|
export const IS_PRIVATE_MANIFOLD = ENV_CONFIG.visibility === 'PRIVATE'
|
2022-05-21 02:34:26 +00:00
|
|
|
|
|
|
|
// Manifold's domain or any subdomains thereof
|
|
|
|
export const CORS_ORIGIN_MANIFOLD = new RegExp(
|
|
|
|
'^https?://(?:[a-zA-Z0-9\\-]+\\.)*' + escapeRegExp(ENV_CONFIG.domain) + '$'
|
|
|
|
)
|
|
|
|
// Any localhost server on any port
|
|
|
|
export const CORS_ORIGIN_LOCALHOST = /^http:\/\/localhost:\d+$/
|