// deno-lint-ignore-file require-await import Logging, { LoggingConfiguration, LogTiming, TimeFormat } from "@proxnet/undead-logging"; import { Hono } from "@hono/hono"; import path from "node:path"; import process from "node:process"; function resDir() { return path.resolve(import.meta.dirname?.concat("/res/") ?? process.cwd()); } LoggingConfiguration.timeFormat = TimeFormat.Unix; LoggingConfiguration.logTiming = LogTiming.Microtask; const log = new Logging("Main"); const CONSTANTS = { page: Deno.readTextFileSync(path.join(resDir(), "index.html")), port: 39392, hostname: Deno.args[0] } const app = new Hono(); let visits = 0; app.get('/', async r => { return r.html(CONSTANTS.page); }); app.get('/hit', async r => { visits++; return r.json(visits); }); app.use('*', async r => { r.status(404); return r.text("Not Found. Sorry! - zombieb"); }); function getSrcAddr(r: Request, addr: Deno.NetAddr) { const cf = r.headers.get("Cf-Connecting-Ip"); if (cf) return cf; else return `${addr.hostname}:${addr.port}`; } Deno.serve({ port: CONSTANTS.port, hostname: CONSTANTS.hostname, onListen: n => { log.i(`Listening information: ${JSON.stringify(n)}`); } }, async (r, addr) => { const url = new URL(r.url); log.n(`${getSrcAddr(r, addr.remoteAddr)} ${r.method} ${url.pathname}${url.searchParams.size > 0 ? `?${url.searchParams.toString()}` : ''}`); return await app.fetch(r); });