#358 Redo port, add default address.
This commit is contained in:
parent
fa1896869e
commit
285da613e4
|
|
@ -191,13 +191,19 @@ namespace Microsoft.AspNet.Hosting.Internal
|
||||||
var builder = builderFactory.CreateBuilder(_serverInstance);
|
var builder = builderFactory.CreateBuilder(_serverInstance);
|
||||||
builder.ApplicationServices = _applicationServices;
|
builder.ApplicationServices = _applicationServices;
|
||||||
|
|
||||||
var port = _config[ServerPort];
|
var addresses = builder.ServerFeatures?.Get<IServerAddressesFeature>()?.Addresses;
|
||||||
if (!string.IsNullOrEmpty(port))
|
if (addresses != null && !addresses.IsReadOnly)
|
||||||
{
|
{
|
||||||
var addresses = builder.ServerFeatures.Get<IServerAddressesFeature>()?.Addresses;
|
var port = _config[ServerPort];
|
||||||
if (addresses != null && !addresses.IsReadOnly)
|
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,24 @@ namespace Microsoft.AspNet.Hosting
|
||||||
var host = CreateBuilder(config).Build();
|
var host = CreateBuilder(config).Build();
|
||||||
var app = host.Start();
|
var app = host.Start();
|
||||||
Assert.NotNull(host.ApplicationServices.GetRequiredService<IHostingEnvironment>());
|
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]
|
[Fact]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue