Skip to content

Commit 56327d4

Browse files
shrn01Sharan J
and
Sharan J
authored
Added functionality - Detect file system change and auto reload the server for Tutorials (ronreiter#711)
Co-authored-by: Sharan J <shrn@DESKTOP-7505097>
1 parent 8c64c39 commit 56327d4

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

Diff for: main.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,21 @@ def error404():
281281
), 404)
282282

283283

284+
# We are checking only the current domain subfolder and adding all the files to files_to_track array
285+
# so that they can be tracked and on change of any of these files, reload the server in real time
286+
def get_filenames_to_watch_and_reload():
287+
dir_to_look = "tutorials/" + current_domain
288+
files_to_track = []
289+
290+
for dirname, dirs, files in os.walk(dir_to_look):
291+
for filename in files:
292+
filename = os.path.join(dirname, filename)
293+
if os.path.isfile(filename):
294+
files_to_track.append(filename)
295+
296+
return files_to_track
297+
298+
284299
@app.route("/favicon.ico")
285300
def favicon():
286301
return open(os.path.join(os.path.dirname(__file__), get_domain_data()["favicon"][1:]), "rb").read()
@@ -432,4 +447,6 @@ def robots():
432447

433448
if __name__ == "__main__":
434449
logging.info("listening on port %s", args.port)
435-
app.run(debug=True, port=args.port, host=args.host)
450+
451+
# The extra_files attribute enables us to provide file names which need to be tracked on change, trigger server reload
452+
app.run(debug=True, port=args.port, host=args.host, extra_files=get_filenames_to_watch_and_reload())

0 commit comments

Comments
 (0)