-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserve.py
49 lines (39 loc) · 1.33 KB
/
serve.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# pip install libsass watchdog
import sass
from http.server import SimpleHTTPRequestHandler, HTTPServer
from functools import partial
import mimetypes
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
def compile_scss():
try:
css = sass.compile(filename="./scss/custom.scss", output_style='compressed')
with open("./wwwroot/custom.css", "w") as f:
f.write(css)
print("css updated")
except Exception:
pass
compile_scss()
class FileChangeEventHandler(FileSystemEventHandler):
def on_any_event(self, event):
compile_scss()
observer = Observer()
observer.schedule(FileChangeEventHandler(), "scss", recursive=False)
observer.start()
class RequestHandler(SimpleHTTPRequestHandler):
def __init__(self, *args, **kwargs):
super().__init__(*args, directory="./wwwroot", **kwargs)
if not mimetypes.inited:
mimetypes.init() # try to read system mime.types
extensions_map = mimetypes.types_map.copy()
extensions_map.update({
'': 'application/octet-stream', # Default
'.py': 'text/plain',
'.c': 'text/plain',
'.h': 'text/plain',
'.js': 'application/javascript',
})
handler_class = RequestHandler
httpd = HTTPServer(('', 8000), handler_class)
httpd.serve_forever()
observer.join()