Skip to content

Commit

Permalink
Improve env variables handling and docs
Browse files Browse the repository at this point in the history
Signed-off-by: Olga Bulat <[email protected]>
  • Loading branch information
obulat committed Jul 29, 2024
1 parent 582cb2d commit 8768c02
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
34 changes: 31 additions & 3 deletions frontend/.env.template
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
PORT=8443

# ---------------------------- #
# REQUIRED LOCAL ENV VARIABLES
# REQUIRED LOCAL ENV VARIABLES #
# ---------------------------- #
# NUXT_PUBLIC_PLAUSIBLE_DOMAIN = localhost
# DEPLOYMENT_ENV=local
# SITE_DOMAIN=localhost
# SITE_URL=http://localhost:8443
#/**
#* We rely on the Nginx container running as `frontend_nginx`
#* in the local compose stack to proxy requests. Therefore, the
Expand All @@ -15,7 +17,7 @@ PORT=8443
#* made to the root URL (openverse.org), and is configured to
#* forward Plausible requests to upstream Plausible.
#*/
# NUXT_PUBLIC_PLAUSIBLE_API_HOST = http://localhost:50290
# PLAUSIBLE_SITE_URL = http://localhost:50290

# ---------------------------- #
# OPTIONAL LOCAL ENV VARIABLES
Expand All @@ -28,3 +30,29 @@ PORT=8443

# NUXT_API_CLIENT_ID=""
# NUXT_API_CLIENT_SECRET=""

# -------------------- #
# PRODUCTION VARIABLES #
# -------------------- #
# DEPLOYMENT_ENV=production
# NUXT_API_CLIENT_ID=""
# NUXT_API_CLIENT_SECRET=""
# NUXT_PUBLIC_API_URL=https://api.openverse.org/
# NUXT_PUBLIC_SENTRY_DSN=""
# NUXT_PUBLIC_SENTRY_RELEASE=""
# SITE_URL=https://openverse.org
# SITE_DOMAIN=openverse.org
# PLAUSIBLE_SITE_URL=https://openverse.org

# ----------------- #
# STAGING VARIABLES #
# ----------------- #
# DEPLOYMENT_ENV=staging
# NUXT_API_CLIENT_ID=""
# NUXT_API_CLIENT_SECRET=""
# NUXT_PUBLIC_API_URL=https://api-staging.openverse.org/
# NUXT_PUBLIC_SENTRY_DSN=""
# NUXT_PUBLIC_SENTRY_RELEASE=""
# SITE_URL=https://staging.openverse.org
# SITE_DOMAIN=staging.openverse.org
# PLAUSIBLE_SITE_URL=https://staging.openverse.org
7 changes: 4 additions & 3 deletions frontend/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const isProductionBuild = import.meta.env.NODE_ENV === "production"
const isPlaywright = import.meta.env.PW === "true"
const isProdNotPlaywright = isProductionBuild && !isPlaywright
const isTest = import.meta.env.TEST === "true"
const deploymentEnv = import.meta.env.DEPLOYMENT_ENV || LOCAL

const apiUrl =
import.meta.env.NUXT_PUBLIC_API_URL || "https://api.openverse.org/"
Expand Down Expand Up @@ -126,20 +127,20 @@ export default defineNuxtConfig({
apiClientSecret: "",
public: {
// These values can be overridden by the NUXT_PUBLIC_* env variables
deploymentEnv: LOCAL,
deploymentEnv,
apiUrl,
providerUpdateFrequency: 3600000,
savedSearchCount: 4,
sentry: {
dsn: "",
environment: import.meta.env.DEPLOYMENT_ENV ?? LOCAL,
environment: deploymentEnv,
release: import.meta.env.SEMANTIC_VERSION,
},
isPlaywright,
},
},
site: {
indexable: import.meta.env.DEPLOYMENT_ENV === PRODUCTION,
indexable: deploymentEnv === PRODUCTION,
trailingSlash: false,
},
/**
Expand Down
4 changes: 2 additions & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"docker:build": "docker build . -t openverse-frontend:latest",
"docker:run": "docker run --rm -it -p 127.0.0.1:8443:8443/tcp openverse-frontend:latest",
"generate": "nuxt generate",
"start": "PORT=\"${PORT:-8443}\" CONSOLA_LEVEL=\"${CONSOLA_LEVEL:-1}\" NUXT_PUBLIC_API_URL=\"${NUXT_PUBLIC_API_URL=https://api.openverse.org/}\" node .output/server/index.mjs",
"start:mem": "PORT=\"${PORT:-8443}\" CONSOLA_LEVEL=\"${CONSOLA_LEVEL:-1}\" NUXT_PUBLIC_API_URL=\"${NUXT_PUBLIC_API_URL=https://api.openverse.org/}\" node --inspect .output/server/index.mjs",
"start": "PORT=\"${PORT:-8443}\" CONSOLA_LEVEL=\"${CONSOLA_LEVEL:-1}\" node .output/server/index.mjs",
"start:mem": "PORT=\"${PORT:-8443}\" CONSOLA_LEVEL=\"${CONSOLA_LEVEL:-1}\" node --inspect .output/server/index.mjs",
"start:playwright": "pnpm i18n:copy-test-locales && pnpm start",
"prod": "pnpm build && pnpm start",
"prod:playwright": "pnpm i18n:copy-test-locales && pnpm prod",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/utils/console.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PRODUCTION, STAGING } from "~/constants/deploy-env"

const isProductionOrStaging = [PRODUCTION, STAGING].includes(
import.meta.env.NODE_ENV
import.meta.env.DEPLOYMENT_ENV
)

/**
Expand Down

0 comments on commit 8768c02

Please sign in to comment.