-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
62 lines (53 loc) · 2.25 KB
/
Copy pathProgram.cs
File metadata and controls
62 lines (53 loc) · 2.25 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using CanvasApp.Components;
using DrupalCanvas.Headless;
using DrupalCanvas.Headless.AspNetCore;
using Microsoft.AspNetCore.Http.HttpResults;
var builder = WebApplication.CreateBuilder(args);
// Loads CANVAS_SITE_URL (and friends) from .env; see .env.example. Real
// environment variables win over the file.
builder.Configuration.AddDotEnvFile();
builder.Services.AddRazorComponents();
builder.Services.AddDrupalCanvasHeadless(options =>
{
options.BaseUrl = builder.Configuration["CANVAS_SITE_URL"];
// The editor's component thumbnails render in an isolated document; give
// it the app's stylesheet so components look the way they do on pages.
options.ComponentPreviewStylesheets.Add("/css/app.css");
});
builder.Services.AddDrupalCanvasComponents(components => components
// Explicit registrations for the components whose class cannot share the
// machine name: a C# property may not be named after its own class, and
// these components carry a prop named exactly like the component.
.Add<CanvasApp.Canvas.HeadingComponent>("heading")
.Add<CanvasApp.Canvas.ImageComponent>("image")
.Add<CanvasApp.Canvas.TextComponent>("text")
.Add<CanvasApp.Canvas.VideoComponent>("video")
.AddFromAssembly(typeof(Program).Assembly, builder.Environment.ContentRootPath));
var app = builder.Build();
app.UseStaticFiles();
app.UseDrupalCanvasFrameAncestors();
app.MapDrupalCanvasHeadless();
// Catch-all Drupal page rendering: resolve the requested path through the
// Canvas content API and render the answer with the Blazor component tree.
app.MapFallback(async (HttpContext context, DraftServer server) =>
{
var path = (context.Request.Path.Value ?? "/") + context.Request.QueryString;
var result = await server.FetchPageAsync(path);
if (result is PageRedirect redirect)
{
context.Response.StatusCode = redirect.Redirect.StatusCode;
context.Response.Headers.Location = redirect.Redirect.Url;
return Results.Empty;
}
var page = result as Page;
if (page is null)
{
context.Response.StatusCode = 404;
}
return new RazorComponentResult<CanvasPage>(new Dictionary<string, object?>
{
[nameof(CanvasPage.Page)] = page,
[nameof(CanvasPage.Path)] = path,
});
});
app.Run();