Added tailwind look option.
This commit is contained in:
+41
-6
@@ -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 = """<!doctype html>
|
||||
"""
|
||||
|
||||
|
||||
VALID_LOOKS = ("basic", "nice", "bootstrap")
|
||||
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>
|
||||
"""
|
||||
|
||||
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user