diff --git a/README.md b/README.md index 56752b2..7bc110b 100644 --- a/README.md +++ b/README.md @@ -19,18 +19,17 @@ To run the server from the command line: ```bash python3 ok-server.py python3 ok-server.py --look basic -python3 ok-server.py --bind 127.0.0.1 --port 8080 --look bootstrap +python3 ok-server.py --bind 127.0.0.1 --port 8080 --look tailwind ``` -`--look` accepts `basic`, `nice`, or `bootstrap`. +`--look` accepts `basic`, `nice`, `bootstrap`, or `tailwind`. You can override the look per request with the `look` query parameter, for example: - -or +`http://localhost:8080/?look=tailwind` ```bash node ok-server.mjs node ok-server.mjs --look basic -node ok-server.mjs --bind 127.0.0.1 --port 8080 --look bootstrap +node ok-server.mjs --bind 127.0.0.1 --port 8080 --look tailwind ``` Connect to the server using a web browser or a tool like `curl`: diff --git a/ok-server.mjs b/ok-server.mjs index 366bcc5..b86de00 100755 --- a/ok-server.mjs +++ b/ok-server.mjs @@ -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 = ` `; +const HTML_TAILWIND = ` + + + + + Test HTTP server + + + +
+
+
+

Test HTTP server

+

Simple status page for firewall/testing

+
+
+

Hello,

+

This is a test HTTP server.

+

Your request came from {ip}.

+ {proxy_headers_html} +

Have a nice day!

+
+
+
+ + +`; + function escapeHtml(value) { return String(value) .replace(/&/g, "&") @@ -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", diff --git a/ok-server.py b/ok-server.py index 8b15fbb..6b70fb9 100755 --- a/ok-server.py +++ b/ok-server.py @@ -11,13 +11,14 @@ Behavior: * 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 the command-line --look - for that request only. Values are case-insensitive and must be one of basic,nice,bootstrap. + for that request only. Values are case-insensitive and must be one of basic,nice,bootstrap,tailwind. Usage: python3 ok_server.py # binds 0.0.0.0:8080, nice look python3 ok_server.py --look basic - python3 ok_server.py -b 127.0.0.1 -p 8080 --look bootstrap + python3 ok_server.py -b 127.0.0.1 -p 8080 --look tailwind Test: curl -i http://localhost:8080/ # text/plain for curl @@ -127,7 +128,36 @@ HTML_BOOTSTRAP = """ """ -VALID_LOOKS = ("basic", "nice", "bootstrap") +HTML_TAILWIND = """ + + + + + Test HTTP server + + + +
+
+
+

Test HTTP server

+

Simple status page for firewall/testing

+
+
+

Hello,

+

This is a test HTTP server.

+

Your request came from {ip}.

+ {proxy_headers_html} +

Have a nice day!

+
+
+
+ + +""" + + +VALID_LOOKS = ("basic", "nice", "bootstrap", "tailwind") class OkHandler(BaseHTTPRequestHandler): @@ -190,8 +220,13 @@ class OkHandler(BaseHTTPRequestHandler): ip=ip, proxy_headers_html=proxy_headers_html, ) - # fallback to bootstrap - return HTML_BOOTSTRAP.format( + if look == "bootstrap": + return HTML_BOOTSTRAP.format( + ip=ip, + proxy_headers_html=proxy_headers_html, + ) + # fallback to tailwind + return HTML_TAILWIND.format( ip=ip, proxy_headers_html=proxy_headers_html, ) @@ -280,6 +315,6 @@ if __name__ == "__main__": parser.add_argument("-p", "--port", type=int, default=8080, help="Port to listen on (default: 8080)") parser.add_argument("--look", choices=VALID_LOOKS, default=VALID_LOOKS[1], - help="Default HTML look for non-cli agents (basic, nice, bootstrap). Default: nice") + help="Default HTML look for non-cli agents (basic, nice, bootstrap, tailwind). Default: nice") args = parser.parse_args() run(args.bind, args.port, args.look)