|
1 | | -using System; |
2 | | -using System.Collections.Generic; |
3 | | -using System.IO; |
4 | | -using System.Linq; |
5 | | -using System.Threading.Tasks; |
6 | | -using Microsoft.AspNetCore; |
| 1 | +using Microsoft.AspNetCore.Builder; |
7 | 2 | using Microsoft.AspNetCore.Hosting; |
8 | | -using Microsoft.Extensions.Configuration; |
9 | | -using Microsoft.Extensions.Logging; |
| 3 | +using Microsoft.Extensions.DependencyInjection; |
| 4 | +using Microsoft.Extensions.Hosting; |
| 5 | +using SqlToElasticSearchConverter; |
| 6 | +using SqlToElasticSearchConverter.Helpers; |
10 | 7 |
|
11 | | -namespace SqlToElasticSearchConverter { |
12 | | - public class Program { |
13 | | - public static void Main(string[] args) { |
14 | | - CreateWebHostBuilder(args).Build().Run(); |
15 | | - } |
| 8 | +var appArgs = new AppArguments(); |
| 9 | +Parser.ParseArgumentsWithUsage(args, appArgs); |
16 | 10 |
|
17 | | - //public static IWebHostBuilder CreateWebHostBuilder(string[] args) => |
18 | | - // WebHost.CreateDefaultBuilder(args) |
19 | | - // .UseStartup<Startup>(); |
| 11 | +var builder = WebApplication.CreateBuilder(args); |
20 | 12 |
|
| 13 | +// apply custom ports if specified (for Raspberry Pi or other custom setups) |
| 14 | +builder.WebHost.ApplyPorts(appArgs); |
21 | 15 |
|
22 | | - public static IWebHostBuilder CreateWebHostBuilder(string[] args) { |
| 16 | +// Add services to the container. |
| 17 | +builder.Services.AddControllersWithViews(); |
23 | 18 |
|
24 | | - // support for custom ports |
25 | | - var appArgs = new Arguments(); |
26 | | - Parser.ParseArgumentsWithUsage(args, appArgs); |
| 19 | +var app = builder.Build(); |
27 | 20 |
|
28 | | - return WebHost.CreateDefaultBuilder(args) |
29 | | - .ApplyPorts(appArgs) |
30 | | - .UseStartup<Startup>(); |
31 | | - } |
| 21 | +// Configure the HTTP request pipeline. |
| 22 | +if (!app.Environment.IsDevelopment()) |
| 23 | +{ |
| 24 | + app.UseExceptionHandler("/Home/Error"); |
| 25 | + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. |
| 26 | + app.UseHsts(); |
| 27 | +} |
32 | 28 |
|
33 | | - } |
| 29 | +app.UseHttpsRedirection(); |
| 30 | +app.UseRouting(); |
34 | 31 |
|
35 | | - public static class WebHostBuilderExtension { |
36 | | - public static IWebHostBuilder ApplyPorts(this IWebHostBuilder host, Arguments appArgs) { |
37 | | - if (appArgs.Port > 0) { |
38 | | - //host.UseUrls($"http://0.0.0.0:{appArgs.Port}"); |
39 | | - host.UseUrls($"http://*:{appArgs.Port}"); |
40 | | - } |
| 32 | +app.UseAuthorization(); |
41 | 33 |
|
42 | | - return host; |
43 | | - } |
44 | | - } |
| 34 | +app.MapStaticAssets(); |
45 | 35 |
|
46 | | - [CommandLineArguments(CaseSensitive = false)] |
47 | | - public class Arguments { |
48 | | - [Argument(ArgumentType.AtMostOnce, HelpText = "Port", DefaultValue = -1, LongName = "Port", ShortName = "p")] |
49 | | - public int Port; |
50 | | - } |
| 36 | +app.MapControllerRoute( |
| 37 | + name: "default", |
| 38 | + pattern: "{controller=Home}/{action=Index}/{id?}") |
| 39 | + .WithStaticAssets(); |
51 | 40 |
|
52 | 41 |
|
53 | | -} |
| 42 | +app.Run(); |
| 43 | + |
0 commit comments