Use hostname to determine environment.

This commit is contained in:
Robin Huang
2025-08-11 20:30:56 -07:00
committed by Jennifer Weber
parent 164d7aac4d
commit 2de65d7e17
4 changed files with 28 additions and 6 deletions

View File

@@ -15,9 +15,9 @@
<script setup lang="ts">
import Tag from 'primevue/tag'
// Global variable from vite build defined in global.d.ts
// eslint-disable-next-line no-undef
const isStaging = !__USE_PROD_CONFIG__
import { isProductionEnvironment } from '@/config/environment'
const isStaging = !isProductionEnvironment()
</script>
<style scoped>

View File

@@ -1,7 +1,9 @@
export const COMFY_API_BASE_URL = __USE_PROD_CONFIG__
import { isProductionEnvironment } from './environment'
export const COMFY_API_BASE_URL = isProductionEnvironment()
? 'https://api.comfy.org'
: 'https://stagingapi.comfy.org'
export const COMFY_PLATFORM_BASE_URL = __USE_PROD_CONFIG__
export const COMFY_PLATFORM_BASE_URL = isProductionEnvironment()
? 'https://platform.comfy.org'
: 'https://stagingplatform.comfy.org'

18
src/config/environment.ts Normal file
View File

@@ -0,0 +1,18 @@
/**
* Runtime environment configuration that determines if we're in production or staging
* based on the hostname. Replaces the build-time __USE_PROD_CONFIG__ constant.
*/
/**
* Checks if the application is running in production environment
* @returns true if hostname is cloud.comfy.org (production), false otherwise (staging)
*/
export function isProductionEnvironment(): boolean {
// In SSR/Node.js environments or during build, use the environment variable
if (typeof window === 'undefined') {
return process.env.USE_PROD_CONFIG === 'true'
}
// In browser, check the hostname
return window.location.hostname === 'cloud.comfy.org'
}

View File

@@ -1,5 +1,7 @@
import { FirebaseOptions } from 'firebase/app'
import { isProductionEnvironment } from './environment'
const DEV_CONFIG: FirebaseOptions = {
apiKey: 'AIzaSyDa_YMeyzV0SkVe92vBZ1tVikWBmOU5KVE',
authDomain: 'dreamboothy-dev.firebaseapp.com',
@@ -23,6 +25,6 @@ const PROD_CONFIG: FirebaseOptions = {
}
// To test with prod config while using dev server, set USE_PROD_CONFIG=true in .env
export const FIREBASE_CONFIG: FirebaseOptions = __USE_PROD_CONFIG__
export const FIREBASE_CONFIG: FirebaseOptions = isProductionEnvironment()
? PROD_CONFIG
: DEV_CONFIG