From 9a0cff177b87dffcf82ea34e2f8ef9182b8aa2f0 Mon Sep 17 00:00:00 2001 From: Daniel Chalmers Date: Sun, 24 Mar 2024 11:21:19 -0500 Subject: [PATCH] wip --- src/Directory.Build.props | 3 +- src/Try.Core/CompilationService.cs | 3 + src/TryMudBlazor.Client/Routes.razor | 6 ++ src/TryMudBlazor.Client/_Imports.razor | 9 ++- src/TryMudBlazor.Server/Program.cs | 78 ++++++++++++------ .../Properties/launchSettings.json | 22 +++--- src/TryMudBlazor.Server/Startup.cs | 79 ------------------- 7 files changed, 83 insertions(+), 117 deletions(-) create mode 100644 src/TryMudBlazor.Client/Routes.razor delete mode 100644 src/TryMudBlazor.Server/Startup.cs diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 97be2013..99d44c70 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -2,8 +2,7 @@ $(TargetFrameworks);net8.0 - - + enable diff --git a/src/Try.Core/CompilationService.cs b/src/Try.Core/CompilationService.cs index aaa09d67..f01b784d 100644 --- a/src/Try.Core/CompilationService.cs +++ b/src/Try.Core/CompilationService.cs @@ -4,6 +4,7 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; + using System.Diagnostics; using System.IO; using System.Linq; using System.Net.Http; @@ -135,6 +136,8 @@ await Task.WhenAll( { var result = await httpClient.GetAsync($"/_framework/{assemblyName}.dll"); + Console.WriteLine( result.RequestMessage ); + Console.WriteLine( result.StatusCode ); result.EnsureSuccessStatusCode(); streams.TryAdd(assemblyName, await result.Content.ReadAsStreamAsync()); diff --git a/src/TryMudBlazor.Client/Routes.razor b/src/TryMudBlazor.Client/Routes.razor new file mode 100644 index 00000000..302d9d85 --- /dev/null +++ b/src/TryMudBlazor.Client/Routes.razor @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/TryMudBlazor.Client/_Imports.razor b/src/TryMudBlazor.Client/_Imports.razor index 986fc78e..07e82841 100644 --- a/src/TryMudBlazor.Client/_Imports.razor +++ b/src/TryMudBlazor.Client/_Imports.razor @@ -1,7 +1,12 @@ -@using Microsoft.AspNetCore.Components.Forms +@using System.Net.Http +@using System.Net.Http.Json +@using Microsoft.AspNetCore.Components.Forms @using Microsoft.AspNetCore.Components.Routing @using Microsoft.AspNetCore.Components.Web +@using static Microsoft.AspNetCore.Components.Web.RenderMode +@using Microsoft.AspNetCore.Components.Web.Virtualization +@using Microsoft.JSInterop @using TryMudBlazor.Client.Components @using TryMudBlazor.Client.Shared -@using MudBlazor \ No newline at end of file +@using MudBlazor diff --git a/src/TryMudBlazor.Server/Program.cs b/src/TryMudBlazor.Server/Program.cs index ae4e6e27..fceb7fe8 100644 --- a/src/TryMudBlazor.Server/Program.cs +++ b/src/TryMudBlazor.Server/Program.cs @@ -1,26 +1,58 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; - -namespace TryMudBlazor.Server +using MudBlazor.Examples.Data; +using TryMudBlazor.Client; +using TryMudBlazor.Client.Shared; + +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. +builder.Services.AddRazorComponents() + .AddInteractiveServerComponents(); + +builder.Services.AddScoped(); +builder.Services.AddCors(options => { - public class Program - { - public static void Main(string[] args) + options.AddDefaultPolicy( + builder => { - CreateHostBuilder(args).Build().Run(); - } - - public static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) - .ConfigureWebHostDefaults(webBuilder => - { - webBuilder.UseStartup(); - }); - } + builder.WithOrigins("https://www.mudblazor.com", "https://mudblazor.com"); + }); +}); + +builder.Services.AddControllers(); + +var app = builder.Build(); + +if (app.Environment.IsDevelopment()) +{ + app.UseDeveloperExceptionPage(); + app.UseWebAssemblyDebugging(); +} +else +{ + app.UseExceptionHandler("/Error", createScopeForErrors: true); + // 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.UseRouting(); + +app.UseCors(); + +// Needed for wasm project +app.UseBlazorFrameworkFiles(); +app.UseStaticFiles(); + +app.MapControllers(); +// Serve the wasm project if no other matches +app.MapFallbackToFile("index.html"); + +app.UseStaticFiles(); +app.UseAntiforgery(); + +app.MapRazorComponents() + .AddInteractiveServerRenderMode(); + //.AddAdditionalAssemblies([typeof(MainLayout).Assembly]); + +app.Run(); diff --git a/src/TryMudBlazor.Server/Properties/launchSettings.json b/src/TryMudBlazor.Server/Properties/launchSettings.json index 662c4353..12ba73ab 100644 --- a/src/TryMudBlazor.Server/Properties/launchSettings.json +++ b/src/TryMudBlazor.Server/Properties/launchSettings.json @@ -12,20 +12,20 @@ "IIS Express": { "commandName": "IISExpress", "launchBrowser": true, - "launchUrl": "swagger", + "launchUrl": "snippet", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } }, - "Server": { - "commandName": "Project", - "dotnetRunMessages": "true", - "launchBrowser": true, - "launchUrl": "swagger", - "applicationUrl": "https://localhost:5001;http://localhost:5000", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - } + "Server": { + "commandName": "Project", + "dotnetRunMessages": "true", + "launchBrowser": true, + "launchUrl": "snippet", + "applicationUrl": "https://localhost:5001;http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } } } diff --git a/src/TryMudBlazor.Server/Startup.cs b/src/TryMudBlazor.Server/Startup.cs deleted file mode 100644 index 55f15a47..00000000 --- a/src/TryMudBlazor.Server/Startup.cs +++ /dev/null @@ -1,79 +0,0 @@ -namespace TryMudBlazor.Server -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Threading.Tasks; - using Microsoft.AspNetCore.Builder; - using Microsoft.AspNetCore.Hosting; - using Microsoft.AspNetCore.HttpsPolicy; - using Microsoft.AspNetCore.Mvc; - using Microsoft.Extensions.Configuration; - using Microsoft.Extensions.DependencyInjection; - using Microsoft.Extensions.Hosting; - using Microsoft.Extensions.Logging; - using MudBlazor.Examples.Data; - - public class Startup - { - public Startup(IConfiguration configuration) - { - Configuration = configuration; - } - - public IConfiguration Configuration { get; } - - // This method gets called by the runtime. Use this method to add services to the container. - public void ConfigureServices(IServiceCollection services) - { - services.AddScoped(); - services.AddCors(options => - { - options.AddDefaultPolicy( - builder => - { - builder.WithOrigins("https://www.mudblazor.com", "https://mudblazor.com"); - }); - }); - - services.AddControllers(); - } - - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - app.UseWebAssemblyDebugging(); - } - else - { - 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.UseRouting(); - - app.UseCors(); - - // Needed for wasm project - app.UseBlazorFrameworkFiles(); - app.UseStaticFiles(); - - app.UseEndpoints(endpoints => - { - endpoints.MapControllers(); - - // Serve the wasm project if no other matches - endpoints.MapFallbackToFile("index.html"); - }); - - - - } - } -}