Skip to content

Commit

Permalink
Get user-agent from request header
Browse files Browse the repository at this point in the history
  • Loading branch information
prasmussen committed Jul 30, 2024
1 parent ba7f013 commit fa6d8f8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
12 changes: 7 additions & 5 deletions glot_cloudflare/functions/[[page]].ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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":
Expand All @@ -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,
}
}
Expand Down
8 changes: 3 additions & 5 deletions glot_core/src/page/home_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down

0 comments on commit fa6d8f8

Please sign in to comment.