Environments and Asset Variants
Relevant source files
The following files were used as context for generating this wiki page:
GoGovSG uses a single codebase to serve three distinct link shortener environments: Go.gov.sg, for.edu.sg, and for.sg. These environments remain identical in core logic but differ in their branding assets, metadata, and authorized user lists. The system identifies which environment to serve using the ASSET_VARIANT environment variable during the build and deployment processes.
Sources: README.md:27-31, README.md:280-285
Asset Variant Architecture
The application uses the ASSET_VARIANT environment variable to determine which branding configuration to load. This affects the frontend bundle, server-side metadata, and specific utility functions like QR code generation.
Supported Variants
The system supports three specific values for the ASSET_VARIANT variable:
| Variant Key | Primary Domain | Target Audience |
|---|---|---|
gov | go.gov.sg | General Singapore Government |
edu | for.edu.sg | Educational Institutions |
health | for.sg | Healthcare Institutions |
Sources: README.md:27-31, webpack.config.ts:40-44, src/server/serverless/bulk-qrcode-generation/qrCode.js:33-35
Variant Resolution Flow
The following diagram illustrates how the ASSET_VARIANT variable propagates through the build system to select specific assets and configurations.
Frontend Customization
The build process uses Webpack to inject variant-specific resources into the client application.
Webpack Asset Resolution
Webpack aliases the @assets path to point to a specific subdirectory based on the variant. For example, if ASSET_VARIANT is set to gov, imports starting with @assets resolve to src/client/app/assets/gov. This allows components to use generic import paths while the bundler resolves the correct environmental images and styles.
Sources: webpack.config.ts:18, webpack.config.ts:85-87
HTML Templates and Metadata
The system maintains separate HTML entry points for each variant in the /public directory (e.g., index-gov.html, index-health.html). The HtmlWebpackPlugin selects the template corresponding to the active variant and injects specific Open Graph (OG) meta tags defined in the configuration.
| Meta Field | gov | edu | health |
|---|---|---|---|
og:title | Go.gov.sg | For.edu.sg | For.sg |
og:description | Singapore gov link shortener | Education short links | Healthcare short links |
Sources: webpack.config.ts:22-38, webpack.config.ts:143-145, public/index-gov.html, public/index-health.html
Server and Infrastructure Configuration
The backend server reads the ASSET_VARIANT to adjust its display identity and external communication settings.
Server-Side Identity
The server maps the variant to a displayHostname used in user-facing communications and error pages.
- gov: Go.gov.sg
- edu: For.edu.sg
- health: For.sg
Sources: src/server/config.ts:251-256
QR Code Generation
The bulk QR code generation module utilizes the variant to select the appropriate logo and color scheme for the generated image. It employs a darkColorMap to ensure the QR code blocks match the branding of the specific institution type.
const darkColorMap = {
gov: '#384A51',
edu: '#2B2E4A',
health: '#472F40',
}
const logoVariant = `qrlogo-${ASSET_VARIANT}.svg`
Sources: src/server/serverless/bulk-qrcode-generation/qrCode.js:37-45
Infrastructure Environments
GoGovSG operates across three primary deployment stages for each asset variant:
- Local Development: Uses
docker-composeto spin up PostgreSQL and Redis. The Webpack dev server typically listens on port 3000, proxying API requests to the backend on port 8080. - Staging: A pre-production environment used for testing code changes.
- Production: The live environment serving citizens.
Each environment requires a full suite of infrastructure, including a PostgreSQL database (with a replica for redirects), Redis instances for sessions and statistics, and AWS S3 for file storage.
Sources: README.md:46-52, README.md:68-80, src/server/config.ts:14-25
Summary
The Environment and Asset Variant system enables GoGovSG to scale across different government sectors without code duplication. By abstracting branding and configuration into the ASSET_VARIANT parameter, the project maintains consistent logic for link shortening and security while providing tailored experiences for government, education, and health agencies.