forked from fullstackproltd/AspNetCoreSpa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
51 lines (45 loc) · 2.29 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System.IO;
using AspNetCoreSpa.Server;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.AspNetCore;
using System.Net;
using System;
namespace AspNetCoreSpa
{
public class Program
{
public static void Main(string[] args)
{
var host = BuildWebHost(args);
// http://odetocode.com/blogs/scott/archive/2016/09/20/database-migrations-and-seeding-in-asp-net-core.aspx
ProcessDbCommands.Process(args, host);
host.Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseKestrel(options =>
{
options.AddServerHeader = false;
var hostingEnv = (IHostingEnvironment)options.ApplicationServices.GetService(typeof(IHostingEnvironment));
// These bindings are overritten by IIS if that is the hosted server
// But if deployed using Docker then in production default address (http://localhost:5000) is used i.e with localhost rather IP address
// This is the reason why IPAddress (127.0.0.1) is only used for local dev only and https address is enabled by explicitly setting flag EnableDevHttps
if (hostingEnv.IsDevelopment())
{
options.Listen(IPAddress.Loopback, 5000);
if (Convert.ToBoolean(Startup.Configuration["EnableDevHttps"]))
{
options.Listen(IPAddress.Loopback, 5001, listenOptions =>
{
// A self-signed certificate can be generated from this project
// https://www.pluralsight.com/blog/software-development/selfcert-create-a-self-signed-certificate-interactively-gui-or-programmatically-in-net
listenOptions.UseHttps("extra/aspnetcorespa.pfx", "aspnetcorespa");
});
}
}
})
.Build();
}
}