switch dev server to nginx
This commit is contained in:
parent
4ae3c527ba
commit
0045b7e0a4
2
Makefile
2
Makefile
|
|
@ -26,7 +26,7 @@ static/highlight.css: build.py
|
||||||
server: all
|
server: all
|
||||||
-killall flask
|
-killall flask
|
||||||
flask run &
|
flask run &
|
||||||
python server.py $(OUT)
|
nginx -c $$(pwd)/nginx.conf -e stderr
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
-rm -r $(OUT)
|
-rm -r $(OUT)
|
||||||
|
|
|
||||||
25
nginx.conf
Normal file
25
nginx.conf
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
31
server.py
31
server.py
|
|
@ -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()
|
|
||||||
Loading…
Reference in a new issue