#358 Redo port, add default address.

This commit is contained in:
Chris R 2015-09-22 08:46:48 -07:00
parent fa1896869e
commit 285da613e4
2 changed files with 29 additions and 6 deletions

View File

@ -191,13 +191,19 @@ namespace Microsoft.AspNet.Hosting.Internal
var builder = builderFactory.CreateBuilder(_serverInstance);
builder.ApplicationServices = _applicationServices;
var port = _config[ServerPort];
if (!string.IsNullOrEmpty(port))
var addresses = builder.ServerFeatures?.Get<IServerAddressesFeature>()?.Addresses;
if (addresses != null && !addresses.IsReadOnly)
{
var addresses = builder.ServerFeatures.Get<IServerAddressesFeature>()?.Addresses;
if (addresses != null && !addresses.IsReadOnly)
var port = _config[ServerPort];
if (!string.IsNullOrEmpty(port))
{
addresses.Add(port);
addresses.Add("http://localhost:" + port);
}
// Provide a default address if there aren't any configured.
if (addresses.Count == 0)
{
addresses.Add("http://localhost:5000");
}
}

View File

@ -92,7 +92,24 @@ namespace Microsoft.AspNet.Hosting
var host = CreateBuilder(config).Build();
var app = host.Start();
Assert.NotNull(host.ApplicationServices.GetRequiredService<IHostingEnvironment>());
Assert.Equal("abc123", app.ServerFeatures.Get<IServerAddressesFeature>().Addresses.First());
Assert.Equal("http://localhost:abc123", app.ServerFeatures.Get<IServerAddressesFeature>().Addresses.First());
}
[Fact]
public void CanDefaultAddresseIfNotConfigured()
{
var vals = new Dictionary<string, string>
{
{ "Hosting:Server", "Microsoft.AspNet.Hosting.Tests" }
};
var builder = new ConfigurationBuilder()
.AddInMemoryCollection(vals);
var config = builder.Build();
var host = CreateBuilder(config).Build();
var app = host.Start();
Assert.NotNull(host.ApplicationServices.GetRequiredService<IHostingEnvironment>());
Assert.Equal("http://localhost:5000", app.ServerFeatures.Get<IServerAddressesFeature>().Addresses.First());
}
[Fact]