mirror of
https://github.com/CompassConnections/Compass.git
synced 2025-12-23 22:18:43 -05:00
Reload env config after setting env vars
This commit is contained in:
@@ -12,4 +12,4 @@ GEODB_API_KEY=
|
||||
|
||||
# For sending emails (e.g. for user sign up, password reset, notifications, etc.).
|
||||
# Create a free account at https://resend.com and get an API key. Should start with "re_".
|
||||
RESEND_KEY=
|
||||
RESEND_KEY=
|
||||
|
||||
@@ -15,6 +15,8 @@ export function isModId(id: string) {
|
||||
return MOD_IDS.includes(id)
|
||||
}
|
||||
|
||||
export const ENV = isProd() ? 'prod' : 'dev'
|
||||
|
||||
export const LOCAL_WEB_DOMAIN = 'localhost:3000';
|
||||
export const LOCAL_BACKEND_DOMAIN = 'localhost:8088';
|
||||
|
||||
@@ -22,7 +24,26 @@ export const IS_GOOGLE_CLOUD = !!process.env.GOOGLE_CLOUD_PROJECT
|
||||
export const IS_VERCEL = !!process.env.NEXT_PUBLIC_VERCEL
|
||||
export const IS_LOCAL = !IS_GOOGLE_CLOUD && !IS_VERCEL
|
||||
export const HOSTING_ENV = IS_GOOGLE_CLOUD ? 'Google Cloud' : IS_VERCEL ? 'Vercel' : IS_LOCAL ? 'local' : 'unknown'
|
||||
console.log(`Running in ${HOSTING_ENV}`, isProd() ? '(prod)' : '(dev)');
|
||||
console.log(`Running in ${HOSTING_ENV} (${ENV})`,);
|
||||
|
||||
// class MissingKeyError implements Error {
|
||||
// constructor(key: string) {
|
||||
// this.message = `Missing ENV_CONFIG.${key} in ${ENV}. If you're running locally, you most likely want to run in dev mode: yarn dev.`
|
||||
// this.name = 'MissingKeyError'
|
||||
// }
|
||||
//
|
||||
// message: string;
|
||||
// name: string;
|
||||
// }
|
||||
|
||||
// for (const key of ['supabaseAnonKey', 'supabasePwd', 'googleApplicationCredentials'] as const) {
|
||||
// if (!(key in ENV_CONFIG) || ENV_CONFIG[key as keyof typeof ENV_CONFIG] == null) {
|
||||
// throw new MissingKeyError(key)
|
||||
// }
|
||||
// }
|
||||
// if (!ENV_CONFIG.firebaseConfig.apiKey) {
|
||||
// throw new MissingKeyError('firebaseConfig.apiKey')
|
||||
// }
|
||||
|
||||
export const DOMAIN = IS_LOCAL ? LOCAL_WEB_DOMAIN : ENV_CONFIG.domain
|
||||
export const BACKEND_DOMAIN = IS_LOCAL ? LOCAL_BACKEND_DOMAIN : ENV_CONFIG.backendDomain
|
||||
|
||||
@@ -36,11 +36,11 @@ export const PROD_CONFIG: EnvConfig = {
|
||||
domain: 'compassmeet.com',
|
||||
backendDomain: 'api.compassmeet.com',
|
||||
supabaseInstanceId: 'ltzepxnhhnrnvovqblfr',
|
||||
supabaseAnonKey: process.env.NEXT_PUBLIC_SUPABASE_KEY || '',
|
||||
supabasePwd: process.env.SUPABASE_DB_PASSWORD || '',
|
||||
googleApplicationCredentials: process.env.GOOGLE_APPLICATION_CREDENTIALS,
|
||||
supabaseAnonKey: '',
|
||||
supabasePwd: '',
|
||||
googleApplicationCredentials: undefined,
|
||||
firebaseConfig: {
|
||||
apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY || '',
|
||||
apiKey: '',
|
||||
authDomain: "compass-130ba.firebaseapp.com",
|
||||
projectId: "compass-130ba",
|
||||
storageBucket: "compass-130ba.firebasestorage.app",
|
||||
@@ -57,3 +57,12 @@ export const PROD_CONFIG: EnvConfig = {
|
||||
],
|
||||
faviconPath: '/favicon.ico',
|
||||
}
|
||||
|
||||
export const refreshConfig = () => {
|
||||
PROD_CONFIG.supabaseAnonKey = process.env.NEXT_PUBLIC_SUPABASE_KEY || ''
|
||||
PROD_CONFIG.supabasePwd = process.env.SUPABASE_DB_PASSWORD || ''
|
||||
PROD_CONFIG.googleApplicationCredentials = process.env.GOOGLE_APPLICATION_CREDENTIALS
|
||||
PROD_CONFIG.firebaseConfig.apiKey = process.env.NEXT_PUBLIC_FIREBASE_API_KEY || ''
|
||||
}
|
||||
|
||||
refreshConfig()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {SecretManagerServiceClient} from '@google-cloud/secret-manager'
|
||||
import {zip} from 'lodash'
|
||||
import {IS_LOCAL} from "common/envs/constants";
|
||||
import {refreshConfig} from "common/envs/prod";
|
||||
|
||||
// List of secrets that are available to backend (api, functions, scripts, etc.)
|
||||
// Edit them at:
|
||||
@@ -44,6 +45,8 @@ export const getSecrets = async (credentials?: any, ...ids: SecretId[]) => {
|
||||
|
||||
const secretIds = ids.length > 0 ? ids : secrets
|
||||
|
||||
console.log('secretIds', secretIds)
|
||||
|
||||
const fullSecretNames = secretIds.map(
|
||||
(secret: string) =>
|
||||
`${client.projectPath(projectId)}/secrets/${secret}/versions/latest`
|
||||
@@ -70,7 +73,9 @@ export const loadSecretsToEnv = async (credentials?: any) => {
|
||||
for (const [key, value] of Object.entries(allSecrets)) {
|
||||
if (key && value) {
|
||||
process.env[key] = value
|
||||
// console.log(key, value)
|
||||
}
|
||||
}
|
||||
refreshConfig()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user