mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 00:25:42 +02:00
docs/server: simplify using http-server
Co-authored-by: NAHO <90870942+trueNAHO@users.noreply.github.com>
This commit is contained in:
parent
af5a0deadd
commit
28a2abf874
2 changed files with 19 additions and 43 deletions
|
@ -1,21 +1,22 @@
|
||||||
{
|
{
|
||||||
lib,
|
|
||||||
runCommand,
|
|
||||||
makeBinaryWrapper,
|
|
||||||
python3,
|
|
||||||
xdg-utils,
|
|
||||||
docs,
|
docs,
|
||||||
|
http-server,
|
||||||
|
writeShellApplication,
|
||||||
}:
|
}:
|
||||||
runCommand "serve-docs"
|
writeShellApplication {
|
||||||
{
|
name = "serve-docs";
|
||||||
nativeBuildInputs = [ makeBinaryWrapper ];
|
runtimeInputs = [ http-server ];
|
||||||
meta.mainProgram = "server";
|
runtimeEnv.server_flags = [
|
||||||
}
|
# Search for available port
|
||||||
''
|
"--port=0"
|
||||||
mkdir -p $out/bin
|
|
||||||
makeWrapper ${lib.getExe python3} \
|
# Disable browser cache
|
||||||
$out/bin/server \
|
"-c-1"
|
||||||
--add-flags ${./server.py} \
|
|
||||||
--chdir ${docs} \
|
# Open using xdg-open
|
||||||
--prefix PATH : ${lib.makeBinPath [ xdg-utils ]}
|
"-o"
|
||||||
''
|
];
|
||||||
|
text = ''
|
||||||
|
http-server ${docs} "''${server_flags[@]}"
|
||||||
|
'';
|
||||||
|
}
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
from http.server import HTTPServer, SimpleHTTPRequestHandler
|
|
||||||
from subprocess import call
|
|
||||||
|
|
||||||
PORT = 8000
|
|
||||||
URL = f"http://localhost:{PORT}"
|
|
||||||
|
|
||||||
|
|
||||||
class AutoBrowseHTTPServer(HTTPServer):
|
|
||||||
def server_activate(self):
|
|
||||||
HTTPServer.server_activate(self)
|
|
||||||
print(f"Serving documentation at {URL}")
|
|
||||||
call(["xdg-open", URL])
|
|
||||||
|
|
||||||
|
|
||||||
class UncachedHTTPHandler(SimpleHTTPRequestHandler):
|
|
||||||
def end_headers(self):
|
|
||||||
self.send_header("Cache-Control", "no-cache, no-store, must-revalidate")
|
|
||||||
self.send_header("Pragma", "no-cache")
|
|
||||||
self.send_header("Expires", "0")
|
|
||||||
super().end_headers()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
with AutoBrowseHTTPServer(("", PORT), UncachedHTTPHandler) as httpd:
|
|
||||||
httpd.serve_forever()
|
|
Loading…
Add table
Add a link
Reference in a new issue