Added tailwind look option.

This commit is contained in:
2026-05-09 20:23:34 +02:00
parent 2699efc773
commit a28e6d5f11
3 changed files with 85 additions and 16 deletions
+40 -5
View File
@@ -12,14 +12,15 @@
* * basic - plain HTML with no external references
* * nice - includes Google Font "Noto Sans" (default)
* * bootstrap - Bootstrap 5 layout
* * tailwind - Tailwind CSS via @tailwindcss/browser@latest
* - The URL query parameter "look" (e.g. /?look=nice) overrides --look for
* that request only. Values are case-insensitive and must be basic,nice,bootstrap.
* that request only. Values are case-insensitive and must be basic,nice,bootstrap,tailwind.
*/
import http from "node:http";
import { URL } from "node:url";
const VALID_LOOKS = new Set(["basic", "nice", "bootstrap"]);
const VALID_LOOKS = new Set(["basic", "nice", "bootstrap", "tailwind"]);
const PLAIN_TEMPLATE =
"Hello, This is a test HTTP server.\n\n" +
@@ -108,6 +109,34 @@ const HTML_BOOTSTRAP = `<!doctype html>
</html>
`;
const HTML_TAILWIND = `<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Test HTTP server</title>
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@latest"></script>
</head>
<body class="min-h-screen bg-slate-100 text-slate-900">
<div class="mx-auto max-w-3xl px-4 py-10 sm:py-16">
<div class="overflow-hidden rounded-2xl border border-slate-200 bg-white shadow-lg">
<div class="bg-slate-900 px-6 py-4 text-slate-100">
<h1 class="text-xl font-semibold">Test HTTP server</h1>
<p class="mt-1 text-sm text-slate-300">Simple status page for firewall/testing</p>
</div>
<main class="space-y-4 px-6 py-6">
<p class="text-2xl font-bold">Hello,</p>
<p>This is a test HTTP server.</p>
<p>Your request came from <strong>{ip}</strong>.</p>
{proxy_headers_html}
<p class="pt-2">Have a nice day!</p>
</main>
</div>
</div>
</body>
</html>
`;
function escapeHtml(value) {
return String(value)
.replace(/&/g, "&amp;")
@@ -174,7 +203,13 @@ function proxyMarkup(xHeaders) {
function htmlForLook(look, ip, proxyHeadersHtml) {
const template =
look === "basic" ? HTML_BASIC : look === "nice" ? HTML_NICE : HTML_BOOTSTRAP;
look === "basic"
? HTML_BASIC
: look === "nice"
? HTML_NICE
: look === "bootstrap"
? HTML_BOOTSTRAP
: HTML_TAILWIND;
return template
.replaceAll("{ip}", ip)
@@ -240,7 +275,7 @@ function parseArgs(argv) {
}
const value = String(argv[i]).trim().toLowerCase();
if (!VALID_LOOKS.has(value)) {
throw new Error(`Invalid look: ${argv[i]} (expected one of: basic, nice, bootstrap)`);
throw new Error(`Invalid look: ${argv[i]} (expected one of: basic, nice, bootstrap, tailwind)`);
}
look = value;
continue;
@@ -249,7 +284,7 @@ function parseArgs(argv) {
if (arg === "-h" || arg === "--help") {
const help = [
"Usage:",
" node ok-server.mjs [-b|--bind ADDRESS] [-p|--port PORT] [--look basic|nice|bootstrap]",
" node ok-server.mjs [-b|--bind ADDRESS] [-p|--port PORT] [--look basic|nice|bootstrap|tailwind]",
"",
"Defaults:",
" --bind 0.0.0.0",