-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
40 lines (31 loc) · 1.02 KB
/
Program.cs
File metadata and controls
40 lines (31 loc) · 1.02 KB
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
using SvelteHybridMVC.Core;
using SvelteHybridMVC.Infrastructure.Extensions;
var builder = WebApplication.CreateBuilder(args);
// 1. Configure MVC with Svelte and runtime compilation.
var mvcBuilder = builder.Services.AddControllersWithViews();
mvcBuilder.AddRazorRuntimeCompilation();
// 2. Register core Svelte services.
builder.Services.AddSvelteHybrid(options =>
{
options.EnableSSR = true;
options.HydrationMode = HydrationMode.Selective;
options.WatchForChanges = builder.Environment.IsDevelopment();
});
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
// Svelte SSR endpoint
app.MapGet("/_svelte/ssr/{component}", async (string component, ISvelteRenderer renderer) =>
{
var result = await renderer.RenderAsync(component);
return Results.Content(result, "text/html");
});
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run();