You can instruct the server to watch specific files, directories, or glob patterns. When a change is detected, you can either execute a Python callable or a shell command.
If you provide a string, it is treated as a shell command. You can use the shell helper to redirect the command's output to a file.
server = Server(app)
# Execute a shell command (e.g., compiling LESS to CSS)
server.watch('static/style.less', 'lessc static/style.less static/style.css')
# Execute a Python function
def my_callback():
print('File changed!')
server.watch('config.json', my_callback)
server.serve()
server.watch('static/style.less', 'lessc static/style.less static/style.css')
def my_callback():
print('File changed!')
server.watch('config.json', my_callback)
server.serve()