Skip to content
This repository was archived by the owner on Nov 21, 2018. It is now read-only.

Add kestrel config to CreateDefaultBuilder #250

Merged
merged 1 commit into from
Dec 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 18 additions & 32 deletions samples/SampleApp/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,47 @@
"Kestrel": {
"EndPoints": {
"Http": {
"Address": "127.0.0.1",
"Port": 5000
},
"Url": "http://localhost:5005"
}

// To enable HTTPS using a certificate file, set the path to a .pfx file in
// the "Path" property below and configure the password in user secrets.
// The "Password" property should be set in user secrets.
//"HttpsInlineCertFile": {
// "Address": "127.0.0.1",
// "Port": 5001,
// "Url": "http://localhost:5005"
// "Certificate": {
// "Source": "File",
// "Path": "<path to .pfx file>"
// "Path": "<path to .pfx file>",
// "Password: "<cert password>"
// }
//},

//"HttpsInlineCertStore": {
// "Address": "127.0.0.1",
// "Port": 5002,
// "Url": "http://localhost:5005"
// "Certificate": {
// "Source": "Store",
// "Subject": "",
// "StoreName": "",
// "StoreLocation": "",
// "Store": "",
// "Location": "",
// "AllowInvalid": "" // Set to "true" to allow invalid certificates (e.g. expired)
// }
//},

// To enable this endpoint, set the path to a .pfx file in the "Path" property
// of the "TestCert" certificate defined under the "Certificates" section.
// Configure the password in user secrets.
//"HttpsCertFile": {
// "Address": "127.0.0.1",
// "Port": 5003,
// "Certificate": "TestCert"
// This uses the cert defined under Certificates/Default or the development cert.
//"HttpsDefaultCert": {
// "Url": "http://localhost:5005"
//}

//"HttpsCertStore": {
// "Address": "127.0.0.1",
// "Port": 5004,
// "Certificate": "TestCertInStore"
//},
}
},
"Certificates": {
//"TestCert": {
// "Source": "File",
// "Path": ""
//"Default": {
// "Path": "<file>",
// "Password": "<password>"
//},

//"TestCertInStore": {
// "Source": "Store",
// From cert store:
//"Default": {
// "Subject": "",
// "StoreName": "",
// "StoreLocation": "",
// "Store": "",
// "Location": "",
// "AllowInvalid": "" // Set to "true" to allow invalid certificates (e.g. expired certificates)
//}
}
Expand Down
11 changes: 7 additions & 4 deletions src/Microsoft.AspNetCore/WebHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private static IWebHost StartWith(string url, Action<IServiceCollection> configu
/// </summary>
/// <remarks>
/// The following defaults are applied to the returned <see cref="WebHostBuilder"/>:
/// use Kestrel as the web server,
/// use Kestrel as the web server and configure it using the application's configuration providers,
/// set the <see cref="IHostingEnvironment.ContentRootPath"/> to the result of <see cref="Directory.GetCurrentDirectory()"/>,
/// load <see cref="IConfiguration"/> from 'appsettings.json' and 'appsettings.[<see cref="IHostingEnvironment.EnvironmentName"/>].json',
/// load <see cref="IConfiguration"/> from User Secrets when <see cref="IHostingEnvironment.EnvironmentName"/> is 'Development' using the entry assembly,
Expand All @@ -133,7 +133,7 @@ public static IWebHostBuilder CreateDefaultBuilder() =>
/// </summary>
/// <remarks>
/// The following defaults are applied to the returned <see cref="WebHostBuilder"/>:
/// use Kestrel as the web server,
/// use Kestrel as the web server and configure it using the application's configuration providers,
/// set the <see cref="IHostingEnvironment.ContentRootPath"/> to the result of <see cref="Directory.GetCurrentDirectory()"/>,
/// load <see cref="IConfiguration"/> from 'appsettings.json' and 'appsettings.[<see cref="IHostingEnvironment.EnvironmentName"/>].json',
/// load <see cref="IConfiguration"/> from User Secrets when <see cref="IHostingEnvironment.EnvironmentName"/> is 'Development' using the entry assembly,
Expand All @@ -148,7 +148,10 @@ public static IWebHostBuilder CreateDefaultBuilder() =>
public static IWebHostBuilder CreateDefaultBuilder(string[] args)
{
var builder = new WebHostBuilder()
.UseKestrel()
.UseKestrel((builderContext, options) =>
Copy link
Member

Choose a reason for hiding this comment

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

Update the remarks above (and related ones on other overloads) to mention that Kestrel will be configured, e.g.:
/// use Kestrel as the web server and configure it using the application's configuration providers,

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated

{
options.Configure(builderContext.Configuration.GetSection("Kestrel"));
})
.UseContentRoot(Directory.GetCurrentDirectory())
.ConfigureAppConfiguration((hostingContext, config) =>
{
Expand Down Expand Up @@ -198,7 +201,7 @@ public static IWebHostBuilder CreateDefaultBuilder(string[] args)
/// </summary>
/// <remarks>
/// The following defaults are applied to the returned <see cref="WebHostBuilder"/>:
/// use Kestrel as the web server,
/// use Kestrel as the web server and configure it using the application's configuration providers,
/// set the <see cref="IHostingEnvironment.ContentRootPath"/> to the result of <see cref="Directory.GetCurrentDirectory()"/>,
/// load <see cref="IConfiguration"/> from 'appsettings.json' and 'appsettings.[<see cref="IHostingEnvironment.EnvironmentName"/>].json',
/// load <see cref="IConfiguration"/> from User Secrets when <see cref="IHostingEnvironment.EnvironmentName"/> is 'Development' using the entry assembly,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ await ExecuteTestApp(applicationName, async (deploymentResult, logger) =>
{
// Assert server is Kestrel
Assert.Equal("Kestrel", response.Headers.Server.ToString());

// Set from default config
Assert.Equal("http://localhost:5002/", deploymentResult.ApplicationBaseUri);
// The application name will be sent in response when all asserts succeed in the test app.
Assert.Equal(applicationName, responseText);
}
Expand Down
9 changes: 8 additions & 1 deletion test/TestSites/CreateDefaultBuilderApp/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
{
"settingsKey": "settingsValue"
"settingsKey": "settingsValue",
"Kestrel": {
"Endpoints": {
"HTTP": {
"Url": "http://localhost:5002"
}
}
}
}