diff --git a/Client/.vscode/launch.json b/Client/.vscode/launch.json index a8fffeb..062ee6f 100644 --- a/Client/.vscode/launch.json +++ b/Client/.vscode/launch.json @@ -1,6 +1,31 @@ { "version": "0.2.0", "configurations": [ + { + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md + "name": ".NET Core Launch (web)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/bin/Debug/net7.0/OI.Metrology.Client.dll", + "args": [], + "cwd": "${workspaceFolder}", + "stopAtEntry": false, + // Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser + "serverReadyAction": { + "action": "openExternally", + "pattern": "\\bNow listening on:\\s+(https?://\\S+)" + }, + "env": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "sourceFileMap": { + "/Views": "${workspaceFolder}/Views" + } + }, { "name": "Launch", // opens a edge window, navigates and click debugs on mine "type": "blazorwasm", @@ -30,7 +55,10 @@ "compounds": [ { "name": "* Hot Reload with Debug - Launch", - "configurations": [ "Watch", "Launch" ] + "configurations": [ + "Watch", + "Launch" + ] } ] } \ No newline at end of file diff --git a/Client/OI.Metrology.Client.csproj b/Client/OI.Metrology.Client.csproj index 95ae203..80b4b08 100644 --- a/Client/OI.Metrology.Client.csproj +++ b/Client/OI.Metrology.Client.csproj @@ -1,12 +1,9 @@ - + $(AssemblyName.Replace(' ', '_')) enable enable net7.0 - false - false - service-worker-assets.js @@ -23,7 +20,4 @@ - - - \ No newline at end of file diff --git a/Client/Pages/_Host.cshtml b/Client/Pages/_Host.cshtml new file mode 100644 index 0000000..5265e15 --- /dev/null +++ b/Client/Pages/_Host.cshtml @@ -0,0 +1,36 @@ +@page "/" +@using Microsoft.AspNetCore.Components.Web +@namespace OI.Metrology.Client.Pages +@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers + + + + + + + + + + + + + + + + + +
+ + An error has occurred. This application may no longer respond until reloaded. + + + An unhandled exception has occurred. See browser dev tools for details. + + Reload + 🗙 +
+ + + + + diff --git a/Client/Program.cs b/Client/Program.cs index 641f789..c8b04d0 100644 --- a/Client/Program.cs +++ b/Client/Program.cs @@ -1,44 +1,39 @@ -using Microsoft.AspNetCore.Components.Web; using Microsoft.AspNetCore.Components.WebAssembly.Hosting; using MudBlazor.Services; -using Serilog; -using Serilog.Core; namespace OI.Metrology.Client; internal class Program { - private static async Task Main(string[] args) + private static void Main(string[] args) { - WebAssemblyHostBuilder builder = WebAssemblyHostBuilder.CreateDefault(args); - LoggingLevelSwitch levelSwitch = new(); - LoggerConfiguration loggerConfiguration = new(); - string? apiUrl = builder.Configuration["ApiUrl"]; - // _ = loggerConfiguration.WriteTo.BrowserConsole(); - // _ = loggerConfiguration.MinimumLevel.ControlledBy(levelSwitch); - // _ = loggerConfiguration.Enrich.WithProperty("InstanceId", Guid.NewGuid().ToString("n")); - // _ = loggerConfiguration.WriteTo.BrowserHttp($"{apiUrl}ingest", controlLevelSwitch: levelSwitch); - Log.Logger = loggerConfiguration.CreateLogger(); - Serilog.ILogger log = Log.ForContext(); - try + WebApplicationBuilder builder = WebApplication.CreateBuilder(args); + + // Add services to the container. + _ = builder.Services.AddRazorPages(); + _ = builder.Services.AddServerSideBlazor(); + + _ = builder.Services.AddMudServices(); + + WebApplication app = builder.Build(); + + // Configure the HTTP request pipeline. + if (!app.Environment.IsDevelopment()) { - if (apiUrl is null) - throw new NullReferenceException(nameof(apiUrl)); - - builder.RootComponents.Add("#app"); - builder.RootComponents.Add("head::after"); - - _ = builder.Services.AddScoped(serviceProvider => new HttpClient { BaseAddress = new Uri(apiUrl) }); - _ = builder.Services.AddMudServices(); - - log.Information("Building Web Host"); - WebAssemblyHost app = builder.Build(); - await app.RunAsync(); - } - catch (Exception ex) - { - log.Fatal(ex, "An exception occurred while creating the WASM host"); - throw; + _ = app.UseExceptionHandler("/Error"); + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. + _ = app.UseHsts(); } + + _ = app.UseHttpsRedirection(); + + _ = app.UseStaticFiles(); + + _ = app.UseRouting(); + + _ = app.MapBlazorHub(); + _ = app.MapFallbackToPage("/_Host"); + + app.Run(); } } \ No newline at end of file