forked from markjprice/cs14net10
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
78 lines (59 loc) · 2.14 KB
/
Program.cs
File metadata and controls
78 lines (59 loc) · 2.14 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using Northwind.EntityModels; // To use AddNorthwindContext method.
using Northwind.Web.Components; // To use App.
// To use StaticWebAssetsLoader.
using Microsoft.AspNetCore.Hosting.StaticWebAssets;
#region Configure the web server host and services.
var builder = WebApplication.CreateBuilder(args);
// Only necessary if you want to switch environments during development.
StaticWebAssetsLoader.UseStaticWebAssets(
builder.Environment, builder.Configuration);
builder.Services.AddRazorComponents();
builder.Services.AddNorthwindContext();
var app = builder.Build();
#endregion
#region Configure the HTTP pipeline and routes
if (!app.Environment.IsDevelopment())
{
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseAntiforgery();
app.UseDefaultFiles(); // index.html, default.html, and so on.
//app.UseStaticFiles(); // .NET 8 or earlier.
app.MapStaticAssets(); // .NET 9 or later.
app.MapRazorComponents<App>();
app.MapGet("/env", () =>
$"Environment is {app.Environment.EnvironmentName}");
app.MapGet("/data", () => Results.Json(new
{
firstName = "John",
lastName = "Doe",
age = 30
}));
app.MapGet("/welcome", () => Results.Content(
content: $"""
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<link href="site.css" rel="stylesheet" />
<title>About Northwind Web</title>
</head>
<body>
<div class="container">
<div class="jumbotron">
<h1 class="display-3">About Northwind Web</h1>
<p class="lead">We supply products to our customers.</p>
<img src="categories.jpeg" style="height:200px;width:300px;" />
</div>
</div>
</body>
</html>
""",
contentType: "text/html"));
#endregion
// Start the web server, host the website, and wait for requests.
app.Run(); // This is a thread-blocking call.
WriteLine("This executes after the web server has stopped!");