-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d4f119e
commit 3ca5209
Showing
3 changed files
with
35 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from flask import Flask | ||
|
||
|
||
def inject_devtools(app: Flask): | ||
# Inject livereload script into HTML responses | ||
@app.after_request | ||
def after_request(response): | ||
if response.status_code != 200: | ||
return response | ||
|
||
mimetype = response.mimetype or "" | ||
if not mimetype.startswith("text/html"): | ||
return response | ||
|
||
if not isinstance(response.response, list): | ||
return response | ||
|
||
script = '<script src="http://localhost:35729/livereload.js"></script>' | ||
body = b"".join(response.response).decode() | ||
body = body.replace("</body>", f"{script}</body>") | ||
response.response = [body.encode("utf8")] | ||
response.content_length = len(response.response[0]) | ||
return response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ py-modules = [] | |
[project.optional-dependencies] | ||
dev = [ | ||
"ruff", | ||
"livereload", | ||
] | ||
|
||
[tool.ruff] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters