Skip to content

Instantly share code, notes, and snippets.

@Beej126
Last active April 4, 2020 01:14
Show Gist options
  • Select an option

  • Save Beej126/7fb617d6f1c73e79554e5492b32fdf38 to your computer and use it in GitHub Desktop.

Select an option

Save Beej126/7fb617d6f1c73e79554e5492b32fdf38 to your computer and use it in GitHub Desktop.
aspnet core snips
//ultimately this sever feature stuff isn't available in azure until after startup
var runningHostAddresses = app.ServerFeatures.Get<IServerAddressesFeature>().Addresses.Select(a => new Uri(a).Host);
var isLocalDev = new[] { "127.0.0.1", "localhost" }.Intersect(runningHostAddresses).Count() > 0;
Environment.SetEnvironmentVariable("eComm_Storefront_localdev", isLocalDev.ToString());
_logger.LogInformation($"running on host ips: {string.Join(", ", runningHostAddresses)}");
//
//it's fuzzy to see a good established pattern for doing local overrides for settings retrieved from a web api
//especially since the existing paradigm is based on Azure subscriptions (aka environments) being populated with settings,
//and a "localdev" PER DEVELOPER environment doesn't seem to be an easily retrofitted concept
//further, we probably don't really want to have a full copy of ALL the DEV ENV config per developer anyway...
//it's usually just a one off override here and there
//what i'm doing so far is _roughly_ following the basic established pattern of an environment variable,
//set via launchSettings.json, which drives loading of appsettings.{}.json files.
//note: not initially wrapping a formal model class around this .. model seems overkill so far
//
//a more automatic route is technically feasible but doesn't smell good...
//scan the process list for iisexpress.exe's and automatically obtain locally running api urls
//the bummer is that then turns into some kind of dependency on local process apis and unfortunately finding a commandline is a step or two outside of trivial
//just in case, here's powershell that would obtain the iisexpress config file running by api name:
// Get-CimInstance Win32_Process -Filter "name = 'iisexpress.exe'" | select CommandLine | select-string "/config:`"(.*?)`".*?/site:`"(.*?)`"" | % {$_.Matches[0].Groups[1].Value, $_.Matches[0].Groups[2].Value}
// from there you could run the following line to get the corresponding localhost://port:url which could be popped into the tenant settings by api name
// 'C:\Program Files\IIS Express\appcmd.exe' list sites /apphostconfig:{config file above}
//also, presumably iisexpress is just a historical dependency to be eventually shifted to 'dotnet run'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment