Skip to content

Stage env#283

Open
jigar-f wants to merge 15 commits intomainfrom
jigar/stage-env
Open

Stage env#283
jigar-f wants to merge 15 commits intomainfrom
jigar/stage-env

Conversation

@jigar-f
Copy link
Contributor

@jigar-f jigar-f commented Jan 7, 2026

This pull request refactors how API endpoint URLs are managed throughout the codebase, introducing environment-aware URL selection to support both production and staging environments. The changes centralize URL definitions and logic in the common package, replacing hardcoded URLs in multiple modules. Additionally, the Kindling client is updated to handle staging environments more gracefully, and a utility function for setting environment variables in-memory is added.

Environment-aware URL management:

  • Added ProServerURL, StageProServerURL, BaseURL, and StageBaseURL constants and corresponding GetProServerURL() and GetBaseURL() functions to common/constants.go for dynamic selection of API endpoints based on environment. Also added a Stage() function in common/init.go to detect staging mode. [1] [2]
  • Replaced all hardcoded API URLs in api/api.go, api/subscription.go, api/user.go, config/fetcher.go, and issue/issue.go with calls to the new common.GetProServerURL() and common.GetBaseURL() functions, ensuring correct URLs are used for production or staging. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13]

Kindling client improvements:

  • Updated kindling/client.go so that when running in staging, domain fronting is disabled and the staging API endpoint is added to proxyless hosts, improving reliability against staging server issues.

Environment variable utilities:

  • Added a Set function to common/env/env.go to allow in-memory and OS-level updates of environment variables, making it easier to change environment settings at runtime for testing or configuration purposes.

These changes make the codebase more flexible and robust when switching between production and staging environments, and reduce the risk of errors from hardcoded URLs.

@jigar-f jigar-f self-assigned this Feb 13, 2026
@jigar-f jigar-f marked this pull request as ready for review February 13, 2026 11:18
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request introduces environment-aware API endpoint management to support both production and staging environments. It centralizes URL definitions in the common package and updates all API calls throughout the codebase to use environment-specific URLs. The Kindling HTTP client is also modified to disable domain fronting in staging mode and add the staging server to proxyless hosts.

Changes:

  • Added environment detection (Stage()) and URL getter functions (GetProServerURL(), GetBaseURL()) in the common package
  • Replaced hardcoded API URLs across multiple modules with calls to centralized URL getter functions
  • Modified Kindling client to handle staging environments differently (disabling domain fronting)
  • Added Set() function to env package for runtime environment variable updates
  • Removed unused sing-dns dependency
  • Increased max uncompressed log size from 40 MB to 50 MB in issue reporter

Reviewed changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
common/constants.go Added URL constants for production and staging, with getter functions
common/init.go Added Stage() function for staging environment detection
common/env/env.go Added Set() function for runtime environment variable updates
kindling/client.go Modified to disable domain fronting and use different transports in staging
api/api.go Updated to use centralized URL getters for pro-server and base URLs
api/subscription.go Updated Stripe billing portal URL to use GetProServerURL()
api/user.go Updated OAuth and streaming URLs to use GetBaseURL()
config/fetcher.go Updated config endpoint URL to use GetBaseURL()
issue/issue.go Updated issue reporting URL to use GetBaseURL(); increased max log size
go.mod, go.sum Removed unused sing-dns dependency

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


// Stage returns true if the application is running in staging environment.
func Stage() bool {
e, _ := env.Get[string](env.ENV)
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Stage() function is missing the strings.ToLower() call that is used in Dev() and Prod() functions. This inconsistency could cause the function to fail if the environment variable is set with different casing (e.g., "Stage", "STAGE", "Staging", "STAGING"). For consistency and robustness, the environment variable value should be converted to lowercase before comparison, just like in the other environment detection functions.

Suggested change
e, _ := env.Get[string](env.ENV)
e, _ := env.Get[string](env.ENV)
e = strings.ToLower(e)

Copilot uses AI. Check for mistakes.
Comment on lines +112 to +120
if common.Stage() {
//Disable domain fronting for stage environment to avoid hitting staging server issues due to fronted client failures.
return kindling.NewKindling("radiance",
kindling.WithPanicListener(reporting.PanicListener),
kindling.WithLogWriter(logger),
// Most endpoints use df.iantem.io, but for some historical reasons
// "pro-server" calls still go to api.getiantem.org.
kindling.WithProxyless("df.iantem.io", "api.getiantem.org", "api.staging.iantem.io"),
)
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the staging environment configuration, the AMPCache and DNSTunnel transports are not configured, but they are included in the production configuration. This means staging will lack these fallback transport mechanisms. If this is intentional to simplify staging testing, it should be documented in a comment. If it's unintentional, these transports should be added to the staging configuration as well.

Copilot uses AI. Check for mistakes.
}

if common.Stage() {
//Disable domain fronting for stage environment to avoid hitting staging server issues due to fronted client failures.
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment is missing a space after the double slash. According to Go conventions, there should be a space between "//" and the comment text.

Suggested change
//Disable domain fronting for stage environment to avoid hitting staging server issues due to fronted client failures.
// Disable domain fronting for stage environment to avoid hitting staging server issues due to fronted client failures.

Copilot uses AI. Check for mistakes.
// "pro-server" calls still go to api.getiantem.org.
kindling.WithProxyless("df.iantem.io", "api.getiantem.org"),
kindling.WithDomainFronting(f),
kindling.WithProxyless("df.iantem.io", "api.getiantem.org", "api.staging.iantem.io"),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to also include the staging URL in production?

Comment on lines +94 to +102
// Set updates the env variable in the in-memory map so that subsequent Get calls
// return the new value. This is needed because init() only runs once at startup,
// so os.Setenv alone won't be picked up by Get.
func Set(key Key, value string) {
parseAndSet(key, value)
// Also set in the OS environment for consistency
os.Setenv(key, value)
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this?

This is needed because init() only runs once at startup

This is intentional. The env variables control how some things are configured and so shouldn't be modified after starting. This can also be misleading and adds the potential for bugs in the future as someone will assume that they can change any variable during runtime and have it take affect.

Copy link
Collaborator

@garmr-ulfr garmr-ulfr Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I see, you can't set environment variables on Android and iOS. Instead of introducing a global Set function just to set the environment to "staging", we could just create a file env_mobile.go with the following:

//go:build android || ios

package env

import "os"

func SetStagingEnv() {
	if _, exists := envVars[ENV]; exists {
		return
	}
	envVars[ENV] = "staging"
	os.Setenv(string(ENV), "staging")
}

This will prevent any value from being modified during runtime, explicitly sets it to "staging", and restricts it to mobile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants