Skip to content

Commit 86d4a1d

Browse files
committed
feat: add VITE_ENVIRONMENT variable for environment-specific configuration
1 parent de5ebb4 commit 86d4a1d

File tree

6 files changed

+40
-4
lines changed

6 files changed

+40
-4
lines changed

.env.sample

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ DATABASE_URL=postgresql://catalogi:pg_password@localhost:5432/db
22
API_PORT=3084
33
EXTERNAL_SOFTWARE_DATA_ORIGIN=wikidata
44

5+
# Environment identifier for environment-specific configuration
6+
# Valid values: "local", "dev", "staging", "pre-production", "production"
7+
# Can be used for environment-specific features like Sentry monitoring, logging levels, etc.
8+
# Defaults to "local" if not provided
9+
VITE_ENVIRONMENT=local
10+
511
VITE_HEAD="
612
<title>Catalogi - Local use</title>
713

api/src/env.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const zEnvConfiguration = z.object({
1414
"databaseUrl": z.string(),
1515
"appUrl": z.string().url(),
1616
"isDevEnvironnement": z.boolean().default(false),
17+
"environment": z.enum(["local", "dev", "staging", "pre-production", "production"]).default("local"),
1718
"port": z.coerce.number().optional().default(8080),
1819
"importDataSourceOrigin": z.string().optional().default("wikidata"),
1920
"botUserEmail": z.string().optional(),
@@ -33,6 +34,7 @@ const envConfiguration = zEnvConfiguration.parse({
3334
"port": parseInt(process.env.API_PORT ?? ""),
3435
"appUrl": process.env.APP_URL,
3536
"isDevEnvironnement": process.env.IS_DEV_ENVIRONNEMENT?.toLowerCase() === "true",
37+
"environment": process.env.VITE_ENVIRONMENT,
3638
"importDataSourceOrigin": process.env.IMPORT_DATA_SOURCE_ORIGIN,
3739
"redirectUrl": process.env.REDIRECT_URL,
3840
"databaseUrl": process.env.DATABASE_URL,

deployment-examples/docker-compose/.env.sample

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ EXTERNAL_SOFTWARE_DATA_ORIGIN=wikidata
66
OIDC_ISSUER_URI=https://auth.code.gouv.fr/auth/realms/codegouv
77
OIDC_CLIENT_ID=sill
88

9+
# Environment identifier for environment-specific configuration
10+
# Valid values: "local", "dev", "staging", "pre-production", "production"
11+
# Can be used for environment-specific features like Sentry monitoring, logging levels, etc.
12+
# Defaults to "local" if not provided
13+
VITE_ENVIRONMENT=production
14+
915
VITE_HEAD="
1016
<title>Catalogi - Deployment exemple</title>
1117

docs/6-env-variables-and-customization.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
## Environment variables
99

10-
The following environment variables are used to configure the Catalogi web application.
10+
The following environment variables are used to configure the Catalogi web application.
1111
You can set them in a `.env` file or directly in your environment.
1212

1313
| Variable Name | Required | Default Value | Example Value |
@@ -17,13 +17,33 @@ You can set them in a `.env` file or directly in your environment.
1717
| DATABASE_URL || - | `postgresql://catalogi:pg_password@localhost:5432/catalogi` |
1818
| API_PORT || `8080` | `1234` |
1919
| IS_DEV_ENVIRONNEMENT || `false` | `true` |
20+
| VITE_ENVIRONMENT || `local` | `local`, `dev`, `staging`, `pre-production`, or `production` |
2021
| EXTERNAL_SOFTWARE_DATA_ORIGIN || `wikidata` | `wikidata` or `HAL` |
2122
| INIT_SOFT_FROM_SOURCE || `false` | `true` |
2223
| BOT_AGENT_EMAIL || - | `[email protected]` |
2324
| IMPORT_WIKIDATA || - | `Q123,Q456,Q789` |
2425
| REDIRECT_URL || - | `https://catalogi.example.com` |
2526

26-
There is another variable that is purely for frontend configuration, which can contain HTML code, that will be injected in the `<head>` of the web application. It is useful to add meta tags, or other HTML elements that you want to be present in the head of the page. Note that you cannot use the syntay with backticks '`'.
27+
### VITE_ENVIRONMENT
28+
29+
The `VITE_ENVIRONMENT` variable identifies the deployment environment and is available in both the API (backend) and web (frontend). Valid values are:
30+
- `local` - Local development environment (default)
31+
- `dev` - Development environment
32+
- `staging` - Staging environment
33+
- `pre-production` - Pre-production environment
34+
- `production` - Production environment
35+
36+
This variable can be used to enable environment-specific features and configurations, such as:
37+
- Error monitoring and logging services (e.g., Sentry)
38+
- Analytics and tracking tools
39+
- Feature flags and conditional behavior
40+
- Different API endpoints or service configurations
41+
42+
While Sentry is not currently set up in this project, the `VITE_ENVIRONMENT` variable provides the foundation for integrating such tools if they become frequently requested features.
43+
44+
### VITE_HEAD
45+
46+
There is another variable that is purely for frontend configuration, which can contain HTML code, that will be injected in the `<head>` of the web application. It is useful to add meta tags, or other HTML elements that you want to be present in the head of the page. Note that you cannot use the syntay with backticks '`'.
2747

2848
```
2949
VITE_HEAD="

web/.env.declaration

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
VITE_HEAD="
22
<title>Catalogi</title>
33

4-
<!--
4+
<!--
55
<meta name='title' content='Setup whatever you want'>
6-
<meta name='description' content='Setup whatever you want'>
6+
<meta name='description' content='Setup whatever you want'>
77
-->
88

99
<script defer>
1010
console.log('Default script. You can change VITE_HEAD env variable, to edit what is injected in the <head> of the page.');
1111
</script>
1212
"
13+
VITE_ENVIRONMENT=
1314
VERSION=
1415
NODE_ENV=

web/src/vite-env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type ImportMetaEnv = {
2323
DEV: boolean
2424
PROD: boolean
2525
VITE_HEAD: string
26+
VITE_ENVIRONMENT: string
2627
VERSION: string
2728
NODE_ENV: string
2829
// @user-defined-start

0 commit comments

Comments
 (0)