switch dev server to nginx

This commit is contained in:
caandt 2024-09-18 22:10:48 -05:00
parent 4ae3c527ba
commit 0045b7e0a4
4 changed files with 27 additions and 32 deletions

View file

@ -26,7 +26,7 @@ static/highlight.css: build.py
server: all
-killall flask
flask run &
python server.py $(OUT)
nginx -c $$(pwd)/nginx.conf -e stderr
clean:
-rm -r $(OUT)

25
nginx.conf Normal file
View file

@ -0,0 +1,25 @@
pid /tmp/pid.pid;
daemon off;
events {}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /dev/stdout main;
server {
listen 8080;
server_name localhost;
root /tmp/2h;
location / {
try_files $uri $uri.html $uri/ =404;
autoindex on;
types {
text/html html htm shtml;
text/css css;
application/javascript js;
}
}
}
}

View file

@ -1,31 +0,0 @@
import http.server
import socketserver
import sys
from pathlib import Path
dir = sys.argv[1]
class RequestHandler(http.server.SimpleHTTPRequestHandler):
def __init__(self, *args, **kwargs):
super().__init__(*args, directory=dir, **kwargs)
def do_GET(self):
if Path(f'{dir}/{self.path}').is_dir():
self.path += '/index.html'
elif self.path[-1] != '/' and Path(self.path).suffix == '':
self.path += '.html'
super().do_GET()
port = 8080
server = socketserver.TCPServer(('localhost', port), RequestHandler, False)
server.allow_reuse_port = True
server.allow_reuse_address = True
server.server_bind()
server.server_activate()
try:
print(f'http://localhost:{port}')
server.serve_forever()
except KeyboardInterrupt:
server.shutdown()
server.server_close()

View file

@ -25,5 +25,6 @@ pkgs.mkShell {
packages = with pkgs; [
gnumake
python311
nginx
];
}