mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-04-04 14:53:33 -04:00
Move hosting constants to new file
This commit is contained in:
@@ -65,11 +65,11 @@ import {OpenAPIV3} from 'openapi-types';
|
||||
import {version as pkgVersion} from './../package.json'
|
||||
import {z, ZodFirstPartyTypeKind, ZodTypeAny} from "zod";
|
||||
import {getUser} from "api/get-user";
|
||||
import {IS_LOCAL} from "common/envs/constants";
|
||||
import {localSendTestEmail} from "api/test";
|
||||
import path from "node:path";
|
||||
import {saveSubscriptionMobile} from "api/save-subscription-mobile";
|
||||
import {authGoogle} from "api/auth-google";
|
||||
import {IS_LOCAL} from "common/hosting/constants";
|
||||
|
||||
// const corsOptions: CorsOptions = {
|
||||
// origin: ['*'], // Only allow requests from this domain
|
||||
|
||||
@@ -7,7 +7,7 @@ import {APIError, APIHandler} from './helpers/endpoint'
|
||||
import {getDefaultNotificationPreferences} from 'common/user-notification-preferences'
|
||||
import {removeUndefinedProps} from 'common/util/object'
|
||||
import {generateAvatarUrl} from 'shared/helpers/generate-and-update-avatar-urls'
|
||||
import {IS_LOCAL, RESERVED_PATHS} from 'common/envs/constants'
|
||||
import {RESERVED_PATHS} from 'common/envs/constants'
|
||||
import {getUser, getUserByUsername, log} from 'shared/utils'
|
||||
import {createSupabaseDirectClient} from 'shared/supabase/init'
|
||||
import {insert} from 'shared/supabase/utils'
|
||||
@@ -15,6 +15,7 @@ import {convertPrivateUser, convertUser} from 'common/supabase/users'
|
||||
import {getBucket} from "shared/firebase-utils";
|
||||
import {sendWelcomeEmail} from "email/functions/helpers";
|
||||
import {setLastOnlineTimeUser} from "api/set-last-online-time";
|
||||
import {IS_LOCAL} from "common/hosting/constants";
|
||||
|
||||
export const createUser: APIHandler<'create-user'> = async (
|
||||
props,
|
||||
|
||||
@@ -3,7 +3,7 @@ import * as admin from 'firebase-admin'
|
||||
import {initAdmin} from 'shared/init-admin'
|
||||
import {loadSecretsToEnv} from 'common/secrets'
|
||||
import {log} from 'shared/utils'
|
||||
import {IS_LOCAL} from "common/envs/constants";
|
||||
import {IS_LOCAL} from "common/hosting/constants";
|
||||
import {METRIC_WRITER} from 'shared/monitoring/metric-writer'
|
||||
import {listen as webSocketListen} from 'shared/websockets/server'
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import * as admin from 'firebase-admin'
|
||||
|
||||
|
||||
import {getServiceAccountCredentials} from "shared/firebase-utils";
|
||||
import {IS_LOCAL} from "common/envs/constants";
|
||||
import {IS_LOCAL} from "common/hosting/constants";
|
||||
|
||||
// Locally initialize Firebase Admin.
|
||||
export const initAdmin = () => {
|
||||
|
||||
@@ -2,7 +2,7 @@ import { format } from 'node:util'
|
||||
import { isError, pick, omit } from 'lodash'
|
||||
import { dim, red, yellow } from 'colors/safe'
|
||||
import { getMonitoringContext } from './context'
|
||||
import {IS_GOOGLE_CLOUD} from "common/envs/constants";
|
||||
import {IS_GOOGLE_CLOUD} from "common/hosting/constants";
|
||||
|
||||
// mapping JS log levels (e.g. functions on console object) to GCP log levels
|
||||
const JS_TO_GCP_LEVELS = {
|
||||
|
||||
@@ -4,7 +4,7 @@ import {log} from './log'
|
||||
import {getInstanceInfo, InstanceInfo} from './instance-info'
|
||||
import {chunk} from 'lodash'
|
||||
import {CUSTOM_METRICS, metrics, MetricStore, MetricStoreEntry,} from './metrics'
|
||||
import {IS_GOOGLE_CLOUD} from "common/envs/constants";
|
||||
import {IS_GOOGLE_CLOUD} from "common/hosting/constants";
|
||||
|
||||
// how often metrics are written. GCP says don't write for a single time series
|
||||
// more than once per 5 seconds.
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
ServerMessage,
|
||||
CLIENT_MESSAGE_SCHEMA,
|
||||
} from 'common/api/websockets'
|
||||
import {IS_LOCAL} from "common/envs/constants";
|
||||
import {IS_LOCAL} from "common/hosting/constants";
|
||||
import {getWebsocketUrl} from "common/api/utils";
|
||||
|
||||
// Extend the type definition locally
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import {BACKEND_DOMAIN, IS_LOCAL} from 'common/envs/constants'
|
||||
import {BACKEND_DOMAIN} from 'common/envs/constants'
|
||||
import {IS_LOCAL} from "common/hosting/constants";
|
||||
|
||||
type ErrorCode =
|
||||
| 400 // your input is bad (like zod is mad)
|
||||
|
||||
@@ -1,28 +1,11 @@
|
||||
import {DEV_CONFIG} from './dev'
|
||||
import {PROD_CONFIG} from './prod'
|
||||
import {isProd} from "common/envs/is-prod";
|
||||
import {HOSTING_ENV, IS_LOCAL, IS_LOCAL_ANDROID} from "common/hosting/constants";
|
||||
|
||||
export const MAX_DESCRIPTION_LENGTH = 100000
|
||||
export const MAX_ANSWER_LENGTH = 240
|
||||
|
||||
export const IS_LOCAL_ANDROID = process.env.NEXT_PUBLIC_LOCAL_ANDROID === '1'
|
||||
console.log('IS_LOCAL_ANDROID', IS_LOCAL_ANDROID)
|
||||
|
||||
export const LOCAL_WEB_DOMAIN = `localhost:3000`
|
||||
export const LOCAL_BACKEND_DOMAIN = `${IS_LOCAL_ANDROID ? '10.0.2.2' : 'localhost'}:8088`
|
||||
|
||||
export const IS_WEBVIEW_BUILD = process.env.NEXT_PUBLIC_BUILD_TARGET === 'capacitor'
|
||||
export const IS_GOOGLE_CLOUD = !!process.env.GOOGLE_CLOUD_PROJECT
|
||||
export const IS_VERCEL = !!process.env.NEXT_PUBLIC_VERCEL
|
||||
export const IS_DEPLOYED = IS_GOOGLE_CLOUD || IS_VERCEL || IS_WEBVIEW_BUILD
|
||||
export const IS_LOCAL = !IS_DEPLOYED
|
||||
export const HOSTING_ENV = IS_GOOGLE_CLOUD ? 'Google Cloud' : IS_VERCEL ? 'Vercel' : IS_WEBVIEW_BUILD ? 'Capacitor WebView' : IS_LOCAL ? 'local' : 'unknown'
|
||||
|
||||
if (IS_LOCAL && !process.env.ENVIRONMENT && !process.env.NEXT_PUBLIC_FIREBASE_ENV) {
|
||||
console.warn("No ENVIRONMENT set, defaulting to DEV")
|
||||
process.env.ENVIRONMENT = 'DEV'
|
||||
}
|
||||
|
||||
export const ENV_CONFIG = isProd() ? PROD_CONFIG : DEV_CONFIG
|
||||
|
||||
export function isAdminId(id: string) {
|
||||
@@ -34,7 +17,7 @@ export function isModId(id: string) {
|
||||
}
|
||||
|
||||
export const ENV = isProd() ? 'prod' : 'dev'
|
||||
export const IS_PROD = ENV === 'prod'
|
||||
// export const IS_PROD = ENV === 'prod'
|
||||
export const IS_DEV = ENV === 'dev'
|
||||
|
||||
console.debug(`Running in ${HOSTING_ENV} (${ENV})`,);
|
||||
@@ -58,6 +41,9 @@ console.debug(`Running in ${HOSTING_ENV} (${ENV})`,);
|
||||
// throw new MissingKeyError('firebaseConfig.apiKey')
|
||||
// }
|
||||
|
||||
export const LOCAL_WEB_DOMAIN = `localhost:3000`
|
||||
export const LOCAL_BACKEND_DOMAIN = `${IS_LOCAL_ANDROID ? '10.0.2.2' : 'localhost'}:8088`
|
||||
|
||||
export const DOMAIN = IS_LOCAL ? LOCAL_WEB_DOMAIN : ENV_CONFIG.domain
|
||||
export const WEB_URL = IS_LOCAL ? `http://${LOCAL_WEB_DOMAIN}` : `https://${DOMAIN}`
|
||||
export const BACKEND_DOMAIN = IS_LOCAL ? LOCAL_BACKEND_DOMAIN : ENV_CONFIG.backendDomain
|
||||
|
||||
14
common/src/hosting/constants.ts
Normal file
14
common/src/hosting/constants.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
export const IS_LOCAL_ANDROID = process.env.NEXT_PUBLIC_LOCAL_ANDROID === '1'
|
||||
export const IS_WEBVIEW = !!process.env.NEXT_PUBLIC_WEBVIEW
|
||||
export const IS_GOOGLE_CLOUD = !!process.env.GOOGLE_CLOUD_PROJECT
|
||||
export const IS_VERCEL = !!process.env.NEXT_PUBLIC_VERCEL
|
||||
export const IS_DEPLOYED = IS_GOOGLE_CLOUD || IS_VERCEL || IS_WEBVIEW
|
||||
export const IS_LOCAL = !IS_DEPLOYED
|
||||
export const HOSTING_ENV = IS_GOOGLE_CLOUD ? 'Google Cloud' : IS_VERCEL ? 'Vercel' : IS_WEBVIEW ? 'WebView' : IS_LOCAL ? 'local' : 'unknown'
|
||||
|
||||
if (IS_LOCAL && !process.env.ENVIRONMENT && !process.env.NEXT_PUBLIC_FIREBASE_ENV) {
|
||||
console.warn("No ENVIRONMENT set, defaulting to DEV")
|
||||
process.env.ENVIRONMENT = 'DEV'
|
||||
}
|
||||
|
||||
console.log('IS_LOCAL_ANDROID', IS_LOCAL_ANDROID)
|
||||
@@ -1,7 +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";
|
||||
import {IS_LOCAL} from "common/hosting/constants";
|
||||
|
||||
// List of secrets that are available to backend (api, functions, scripts, etc.)
|
||||
// Edit them at:
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import {Head, Html, Main, NextScript} from 'next/document'
|
||||
import {ENV_CONFIG, IS_DEPLOYED} from 'common/envs/constants'
|
||||
import {ENV_CONFIG} from 'common/envs/constants'
|
||||
import Script from 'next/script'
|
||||
import clsx from "clsx";
|
||||
import {IS_DEPLOYED} from "common/hosting/constants";
|
||||
|
||||
export default function Document() {
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user