FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
website/src/Downpatch.Web/Program.cs at main · downpatch/website · GitHub
downpatch
/
website
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
0
Code
Issues
0
Pull requests
1
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
website
/
src
/
Downpatch.Web
/
Program.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
123 lines (107 loc) · 4.66 KB
Breadcrumbs
website
/
src
/
Downpatch.Web
/
Program.cs
Copy path
File metadata and controls
123 lines (107 loc) · 4.66 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
using
Downpatch
.
Web
.
Components
;
using
Downpatch
.
Web
.
Endpoints
;
using
Downpatch
.
Web
.
Services
;
using
Markdig
;
using
Microsoft
.
AspNetCore
.
HttpOverrides
;
using
Microsoft
.
Extensions
.
FileProviders
;
namespace
Downpatch
.
Web
{
public
class
Program
{
public
static
void
Main
(
string
[
]
args
)
{
var
builder
=
WebApplication
.
CreateBuilder
(
args
)
;
// Add services to the container.
builder
.
Services
.
AddRazorComponents
(
)
;
builder
.
Services
.
AddHttpContextAccessor
(
)
;
builder
.
Services
.
AddRouting
(
)
;
builder
.
Services
.
AddMemoryCache
(
o
=>
{
o
.
SizeLimit
=
512
*
1024
*
1024
;
}
)
;
builder
.
Services
.
AddSingleton
(
sp
=>
{
var
env
=
sp
.
GetRequiredService
<
IHostEnvironment
>
(
)
;
var
root
=
Path
.
GetFullPath
(
Path
.
Combine
(
env
.
ContentRootPath
,
"content"
)
)
;
var
index
=
new
ContentIndex
(
root
)
;
index
.
Build
(
)
;
return
index
;
}
)
;
builder
.
Services
.
AddSingleton
(
sp
=>
{
var
pipeline
=
new
MarkdownPipelineBuilder
(
)
.
DisableHtml
(
)
.
UseAutoIdentifiers
(
Markdig
.
Extensions
.
AutoIdentifiers
.
AutoIdentifierOptions
.
GitHub
)
.
Build
(
)
;
return
pipeline
;
}
)
;
builder
.
Services
.
AddSingleton
(
sp
=>
{
var
env
=
sp
.
GetRequiredService
<
IHostEnvironment
>
(
)
;
var
root
=
Path
.
GetFullPath
(
Path
.
Combine
(
env
.
ContentRootPath
,
"content"
)
)
;
var
nav
=
new
Downpatch
.
Web
.
Services
.
NavStore
(
root
)
;
nav
.
Build
(
)
;
return
nav
;
}
)
;
builder
.
Services
.
AddSingleton
<
MarkdownPageService
>
(
)
;
var
app
=
builder
.
Build
(
)
;
app
.
UseForwardedHeaders
(
new
ForwardedHeadersOptions
{
ForwardedHeaders
=
ForwardedHeaders
.
XForwardedFor
|
ForwardedHeaders
.
XForwardedProto
|
ForwardedHeaders
.
XForwardedHost
}
)
;
var
isDev
=
app
.
Environment
.
IsDevelopment
(
)
;
if
(
app
.
Environment
.
IsDevelopment
(
)
)
{
app
.
Use
(
async
(
ctx
,
next
)
=>
{
ctx
.
Response
.
Headers
[
"Content-Security-Policy"
]
=
"default-src 'self'; "
+
"base-uri 'self'; form-action 'self'; frame-ancestors 'none'; object-src 'none'; "
+
"script-src 'self' 'unsafe-inline'; "
+
"style-src 'self' 'unsafe-inline' https://cdn.jsdelivr.net; "
+
"img-src 'self' data:; font-src 'self' https://cdn.jsdelivr.net data:; "
+
"connect-src 'self' ws: wss: http://localhost:* https://localhost:*"
;
await
next
(
)
;
}
)
;
}
else
{
app
.
Use
(
async
(
ctx
,
next
)
=>
{
ctx
.
Response
.
Headers
[
"Content-Security-Policy"
]
=
"default-src 'self'; "
+
"base-uri 'self'; form-action 'self'; frame-ancestors 'none'; object-src 'none'; "
+
"script-src 'self'; "
+
"style-src 'self' 'unsafe-inline' https://cdn.jsdelivr.net; "
+
"img-src 'self' data:; font-src 'self' https://cdn.jsdelivr.net data:; "
+
"connect-src 'self'"
;
await
next
(
)
;
}
)
;
}
app
.
UseStaticFiles
(
new
StaticFileOptions
{
FileProvider
=
new
PhysicalFileProvider
(
Path
.
Combine
(
app
.
Environment
.
ContentRootPath
,
"content"
)
)
,
RequestPath
=
"/content"
}
)
;
// Configure the HTTP request pipeline.
if
(
!
app
.
Environment
.
IsDevelopment
(
)
)
{
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
.
UseStatusCodePagesWithReExecute
(
"/not-found"
,
createScopeForStatusCodePages
:
true
)
;
app
.
UseHttpsRedirection
(
)
;
app
.
UseAntiforgery
(
)
;
app
.
MapStaticAssets
(
)
;
app
.
UseStaticFiles
(
)
;
app
.
MapRobots
(
)
;
app
.
MapSitemap
(
)
;
app
.
MapRazorComponents
<
App
>
(
)
;
using
var
scope
=
app
.
Services
.
CreateScope
(
)
;
var
pages
=
scope
.
ServiceProvider
.
GetRequiredService
<
Downpatch
.
Web
.
Services
.
MarkdownPageService
>
(
)
;
pages
.
WarmAll
(
)
;
app
.
Run
(
)
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL