Skip to content

fix: Move next/image Allowed Domains to Environment Configuration #417

@karan1633

Description

@karan1633

Problem Statement

The current next.config.js configuration hardcodes image hostnames directly in source code using images.domains.

As Summit supports multiple environments (local, staging, production) and may integrate with different backend systems, this approach introduces unnecessary friction and frequent code changes for what is fundamentally deployment-specific configuration.


Why This Is a Problem

Hardcoding image domains in the codebase leads to:

  • Repeated code changes for environment-specific domain updates
  • Increased risk of build failures when a new image host is introduced
  • Tight coupling between deployment infrastructure and frontend source code
  • Poor DevOps experience for managing environments
  • Reduced flexibility when switching or adding backend/CDN domains

Proposed Solution

Move the list of allowed image hostnames to an environment variable and derive the configuration dynamically in next.config.js.

Example Approach

  • Define an environment variable: NEXT_IMAGE_DOMAINS=example.com,cdn.example.com,assets.example.net
  • Parse and apply it in next.config.js instead of hardcoding domains.

This allows image host configuration to be:

  • Environment-specific
  • Deployment-controlled
  • Code-change-free

Scope of Change

  • Remove hardcoded image domains from next.config.js
  • Introduce a new environment variable for image host configuration
  • Update next.config.js to parse and apply the environment variable
  • Ensure all environments define the variable correctly
  • Document the new configuration requirement

Benefits

  • Cleaner and more maintainable configuration
  • Zero code changes required when image domains change
  • Better separation between code and infrastructure
  • Improved DevOps and contributor experience
  • Safer and more predictable builds

Acceptance Criteria

  • No hardcoded image domains remain in the codebase
  • Image domains are fully driven by an environment variable
  • next/image continues to function correctly across all environments
  • Missing or misconfigured environment variables fail fast with clear errors
  • Documentation is updated to reflect the new setup

Notes

This change affects configuration only and does not alter application behavior or runtime logic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions