ShopPlatform.Web 1.0.0.0
농산물, 소프트웨어 라이선스와 개발 용역을 직접 판매하는 CodeMaru 직영 쇼핑몰입니다.
로딩중...
검색중...
일치하는것 없음
ShopPlatform.Middleware.OgBotMiddleware(RequestDelegate next) 클래스 참조sealed

더 자세히 ...

Public 멤버 함수

async Task InvokeAsync (HttpContext ctx, IShopTenantStore store, ShopOptions opts)

정적 Private 멤버 함수

static bool IsBot (string ua)
static bool IsShopPath (string path, out string slug)
static async Task WriteOgHtml (HttpContext ctx, ShopConfig cfg, ShopOptions opts, string slug)
static string HtmlEncode (string s)

정적 Private 속성

static readonly string[] BotKeywords
static readonly HashSet< string > Reserved

상세한 설명

카카오톡·SNS 크롤러가 /{slug} 에 접근하면 Blazor 없이 OG 메타태그만 담긴 최소 HTML을 즉시 반환합니다. 일반 브라우저는 그대로 통과시킵니다.

OgBotMiddleware.cs 파일의 14 번째 라인에서 정의되었습니다.

멤버 함수 문서화

◆ HtmlEncode()

string ShopPlatform.Middleware.OgBotMiddleware.HtmlEncode ( string s)
inlinestaticprivate

Html Encode 작업을 수행합니다.

매개변수
s이벤트를 발생시킨 객체입니다.
반환값
Html Encode 작업에서 생성한 string 결과입니다.

OgBotMiddleware.cs 파일의 298 번째 라인에서 정의되었습니다.

299 => System.Net.WebUtility.HtmlEncode(s);

다음에 의해서 참조됨 : WriteOgHtml().

이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ InvokeAsync()

async Task ShopPlatform.Middleware.OgBotMiddleware.InvokeAsync ( HttpContext ctx,
IShopTenantStore store,
ShopOptions opts )
inline

Invoke Async 작업을 수행합니다.

매개변수
ctxctx에 사용할 HttpContext 값입니다.
storestore에 사용할 IShopTenantStore 값입니다.
optsopts에 사용할 ShopOptions 값입니다.
반환값
Invoke Async 작업에서 생성한 Task 결과입니다.

OgBotMiddleware.cs 파일의 73 번째 라인에서 정의되었습니다.

74 {
75 var ua = ctx.Request.Headers.UserAgent.ToString().ToLowerInvariant();
76 var path = ctx.Request.Path.Value ?? string.Empty;
77
78 // 봇이고 /{slug} 패턴이면 OG HTML 반환
79 if (IsBot(ua) && IsShopPath(path, out var slug))
80 {
81 var config = await store.GetAsync(slug);
82 if (config != null && config.IsActive)
83 {
84 await WriteOgHtml(ctx, config, opts, slug);
85 return;
86 }
87 }
88
89 await next(ctx);
90 }
Task< ShopConfig?> GetAsync(string slug)

다음을 참조함 : ShopPlatform.Services.IShopTenantStore.GetAsync(), IsBot(), IsShopPath(), WriteOgHtml().

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:

◆ IsBot()

bool ShopPlatform.Middleware.OgBotMiddleware.IsBot ( string ua)
inlinestaticprivate

Is Bot 조건을 확인합니다.

매개변수
uaua에 사용할 string 값입니다.
반환값
Is Bot 조건이 충족되면 true이고, 그렇지 않으면 false입니다.

OgBotMiddleware.cs 파일의 116 번째 라인에서 정의되었습니다.

117 => BotKeywords.Any(k => ua.Contains(k));

다음을 참조함 : BotKeywords.

다음에 의해서 참조됨 : InvokeAsync().

이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ IsShopPath()

bool ShopPlatform.Middleware.OgBotMiddleware.IsShopPath ( string path,
out string slug )
inlinestaticprivate

Is Shop Path 조건을 확인합니다.

매개변수
pathpath에 사용할 string 값입니다.
slugslug에 사용할 string 값입니다.
반환값
Is Shop Path 조건이 충족되면 true이고, 그렇지 않으면 false입니다.

OgBotMiddleware.cs 파일의 165 번째 라인에서 정의되었습니다.

166 {
167 slug = string.Empty;
168 var trimmed = path.Trim('/');
169 // 루트(/) 또는 하위경로 제외, 단일 세그먼트만 처리
170 if (string.IsNullOrEmpty(trimmed) || trimmed.Contains('/')) return false;
171 if (Reserved.Contains(trimmed)) return false;
172 slug = trimmed;
173 return true;
174 }

다음을 참조함 : Reserved.

다음에 의해서 참조됨 : InvokeAsync().

이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ WriteOgHtml()

async Task ShopPlatform.Middleware.OgBotMiddleware.WriteOgHtml ( HttpContext ctx,
ShopConfig cfg,
ShopOptions opts,
string slug )
inlinestaticprivate

Og Html 데이터를 씁니다.

매개변수
ctxctx에 사용할 HttpContext 값입니다.
cfgcfg에 사용할 ShopConfig 값입니다.
optsopts에 사용할 ShopOptions 값입니다.
slugslug에 사용할 string 값입니다.
반환값
Write Og Html 작업에서 생성한 Task 결과입니다.

OgBotMiddleware.cs 파일의 224 번째 라인에서 정의되었습니다.

225 {
226 var baseUrl = opts.BaseUrl.TrimEnd('/');
227 var title = !string.IsNullOrEmpty(cfg.OgTitle) ? cfg.OgTitle : cfg.ShopName;
228 var desc = !string.IsNullOrEmpty(cfg.OgDescription) ? cfg.OgDescription
229 : !string.IsNullOrEmpty(cfg.Description) ? cfg.Description
230 : $"{cfg.ShopName}에서 쇼핑하세요";
231 var url = $"{baseUrl}/{slug}";
232
233 // OG 이미지: OgImagePath → LogoPath → 자동 생성
234 string imgUrl;
235 if (!string.IsNullOrEmpty(cfg.OgImagePath))
236 imgUrl = cfg.OgImagePath.StartsWith("http") ? cfg.OgImagePath : $"{baseUrl}{cfg.OgImagePath}";
237 else if (!string.IsNullOrEmpty(cfg.LogoPath))
238 imgUrl = cfg.LogoPath.StartsWith("http") ? cfg.LogoPath : $"{baseUrl}{cfg.LogoPath}";
239 else
240 imgUrl = $"{baseUrl}/img/og/og-{slug}.png";
241
242 var html = $"""
243 <!DOCTYPE html>
244 <html lang="ko">
245 <head>
246 <meta charset="utf-8" />
247 <title>{HtmlEncode(title)}</title>
248 <meta name="description" content="{HtmlEncode(desc)}" />
249 <meta property="og:type" content="website" />
250 <meta property="og:url" content="{url}" />
251 <meta property="og:title" content="{HtmlEncode(title)}" />
252 <meta property="og:description" content="{HtmlEncode(desc)}" />
253 <meta property="og:image" content="{imgUrl}" />
254 <meta property="og:image:width" content="1200" />
255 <meta property="og:image:height" content="630" />
256 <meta property="og:site_name" content="ShopPlatform" />
257 <meta name="twitter:card" content="summary_large_image" />
258 <meta name="twitter:title" content="{HtmlEncode(title)}" />
259 <meta name="twitter:description" content="{HtmlEncode(desc)}" />
260 <meta name="twitter:image" content="{imgUrl}" />
261 </head>
262 <body>
263 <script>location.href="{url}";</script>
264 <a href="{url}">{HtmlEncode(title)}</a>
265 </body>
266 </html>
267 """;
268
269 ctx.Response.ContentType = "text/html; charset=utf-8";
270 ctx.Response.StatusCode = 200;
271 await ctx.Response.WriteAsync(html);
272 }

다음을 참조함 : ShopPlatform.Models.ShopOptions.BaseUrl, ShopPlatform.Models.ShopConfig.Description, HtmlEncode(), ShopPlatform.Models.ShopConfig.LogoPath, ShopPlatform.Models.ShopConfig.OgDescription, ShopPlatform.Models.ShopConfig.OgImagePath, ShopPlatform.Models.ShopConfig.OgTitle, ShopPlatform.Models.ShopConfig.ShopName.

다음에 의해서 참조됨 : InvokeAsync().

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:
이 함수를 호출하는 함수들에 대한 그래프입니다.:

멤버 데이터 문서화

◆ BotKeywords

readonly string [] ShopPlatform.Middleware.OgBotMiddleware.BotKeywords
staticprivate
초기값:
=
[
"kakaotalk", "facebookexternalhit", "twitterbot", "linkedinbot",
"slackbot", "telegrambot", "whatsapp", "discordbot",
"baiduspider", "yeti", "naverbot", "daumoa",
"googlebot", "bingbot"
]

Bot Keywords 값을 보관합니다.

OgBotMiddleware.cs 파일의 25 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : IsBot().

◆ Reserved

readonly HashSet<string> ShopPlatform.Middleware.OgBotMiddleware.Reserved
staticprivate
초기값:
= new(StringComparer.OrdinalIgnoreCase)
{
"admin", "pay", "healthz", "_framework", "_blazor",
"css", "js", "img", "shop-img", "favicon.ico"
}

Reserved 값을 보관합니다.

OgBotMiddleware.cs 파일의 127 번째 라인에서 정의되었습니다.

128 {
129 "admin", "pay", "healthz", "_framework", "_blazor",
130 "css", "js", "img", "shop-img", "favicon.ico"
131 };

다음에 의해서 참조됨 : IsShopPath().


이 클래스에 대한 문서화 페이지는 다음의 파일로부터 생성되었습니다.: