From fa6d8f8dc4404742eefc326e84d04f4b10cf6bf8 Mon Sep 17 00:00:00 2001 From: Petter Rasmussen Date: Tue, 30 Jul 2024 18:41:26 +0200 Subject: [PATCH] Get user-agent from request header --- glot_cloudflare/functions/[[page]].ts | 12 +++++++----- glot_core/src/page/home_page.rs | 8 +++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/glot_cloudflare/functions/[[page]].ts b/glot_cloudflare/functions/[[page]].ts index 7dc7893..f14ff1a 100644 --- a/glot_cloudflare/functions/[[page]].ts +++ b/glot_cloudflare/functions/[[page]].ts @@ -2,7 +2,7 @@ import * as glot from "../dist_backend/wasm_backend/glot"; export async function onRequest({ request }) { const route = glot.getRouteName(request.url); - const { page, status } = getPageConfig(route, request.url); + const { page, status } = getPageConfig(route, request); const { model, effects } = page.init(); const html = page.view(model); @@ -23,8 +23,10 @@ interface PageConfig { status: number; } -function getPageConfig(route: string, url: any): PageConfig { +function getPageConfig(route: string, request: any): PageConfig { const windowSize = null; + const url = request.url; + const userAgent = request.headers.get("user-agent"); switch (route) { case "NotFound": @@ -35,19 +37,19 @@ function getPageConfig(route: string, url: any): PageConfig { case "Home": return { - page: glot.homePage("cloudflare", url), + page: glot.homePage(userAgent, url), status: 200, } case "NewSnippet": return { - page: glot.snippetPage(windowSize, "cloudflare", url), + page: glot.snippetPage(windowSize, userAgent, url), status: 200, } case "EditSnippet": return { - page: glot.snippetPage(windowSize, "cloudflare", url), + page: glot.snippetPage(windowSize, userAgent, url), status: 200, } } diff --git a/glot_core/src/page/home_page.rs b/glot_core/src/page/home_page.rs index fad3eac..eaa53ef 100644 --- a/glot_core/src/page/home_page.rs +++ b/glot_core/src/page/home_page.rs @@ -274,11 +274,9 @@ fn view_search_button(model: &Model) -> Markup { span class="flex-auto" { "Quick action..." } - @if model.user_agent.os != OperatingSystem::Cloudflare { - kbd class="font-sans font-semibold dark:text-slate-500" { - abbr class="no-underline text-slate-300 dark:text-slate-500" title="Command" { - (key_combo) - } + kbd class="font-sans font-semibold dark:text-slate-500" { + abbr class="no-underline text-slate-300 dark:text-slate-500" title="Command" { + (key_combo) } } }