Simple API gateway for webhooks
at main 1.9 kB view raw
1import { Hono } from "hono" 2import { uaBlocker } from "@hono/ua-blocker" 3import { aiBots, useAiRobotsTxt } from "@hono/ua-blocker/ai-bots" 4import { config } from "../config.ts" 5import { sensors } from "./sensors.ts" 6import { kv } from "./util.ts" 7 8const app = new Hono() 9 .route("/sensors", sensors) 10 .get("/robots.txt", useAiRobotsTxt()) 11 .use( 12 "*", 13 uaBlocker({ 14 blocklist: aiBots, 15 }), 16 ) 17 .get("/", (ctx) => { 18 return ctx.html(` 19 <html> 20 <head> 21 <title>${config.title || "auth server"}</title> 22 <style> 23 body { 24 font-family: Arial, sans-serif; 25 margin: 0; 26 padding: 0; 27 background-color: #f5f5f5; 28 display: flex; 29 flex-direction: column; 30 justify-content: center; 31 align-items: center; 32 height: 100svh; 33 } 34 h1 { 35 font-size: 3rem; 36 color: #333; 37 text-align: center; 38 } 39 p { 40 font-size: 1.2rem; 41 color: #666; 42 text-align: center; 43 } 44 </style> 45 </head> 46 <body> 47 <h1>${config.title || "auth server"}</h1> 48 <p> 49 ${config.description || "This is a simple auth server"} 50 </p> 51 </body> 52 </html> 53 `) 54 }) 55 56if (Deno.env.get("DENO_ENV") === "dev") { 57 const { default: data } = await import("../test.json", { with: { type: "json" } }) 58 kv.set( 59 ["sensors", "latest"], 60 { ...data }, 61 ) 62} 63 64Deno.serve(app.fetch)