thomasht86 commited on
Commit
0134a3f
·
verified ·
1 Parent(s): b7d5a9b

deploy at 2024-08-23 17:26:09.547780

Browse files
Files changed (1) hide show
  1. main.py +9 -8
main.py CHANGED
@@ -145,14 +145,19 @@ headers = (
145
  spinner_css,
146
  )
147
 
 
 
 
 
 
 
148
  # Sesskey
149
  sess_key_path = "session/.sesskey"
150
  # Make sure session directory exists
151
  os.makedirs("session", exist_ok=True)
152
 
153
- # Middleware
154
-
155
 
 
156
  class XFrameOptionsMiddleware(BaseHTTPMiddleware):
157
  async def dispatch(self, request, call_next):
158
  response = await call_next(request)
@@ -742,8 +747,6 @@ def get_admin(auth, page: int = 1):
742
 
743
  @app.get("/source")
744
  def get_source(auth, sess):
745
- with open("main.py") as f:
746
- source = f.read()
747
  # Back icon to go back to main page in top left corner
748
  return (
749
  Title("Source code"),
@@ -758,7 +761,7 @@ def get_source(auth, sess):
758
  style="margin: 10px;",
759
  ),
760
  Div(
761
- f"""### main.py - This is the whole source code for this app (!)\n```python\n{source}\n```""",
762
  cls="marked",
763
  style="margin: 10px;",
764
  ),
@@ -770,11 +773,9 @@ def get_source(auth, sess):
770
 
771
  @app.get("/about")
772
  def get_about(auth, sess):
773
- with open("README.md") as f:
774
- readme = f.read()
775
  # Strip everything before the FIRST # in the README
776
  stripped_readme = re.sub(
777
- r"^.*?(?=# FastHTML Vespa frontend)", "", readme, flags=re.DOTALL
778
  )
779
 
780
  return (
 
145
  spinner_css,
146
  )
147
 
148
+ # Read file contents once before starting the server
149
+ with open("README.md") as f:
150
+ README = f.read()
151
+ with open("main.py") as f:
152
+ SOURCE = f.read()
153
+
154
  # Sesskey
155
  sess_key_path = "session/.sesskey"
156
  # Make sure session directory exists
157
  os.makedirs("session", exist_ok=True)
158
 
 
 
159
 
160
+ # Middleware
161
  class XFrameOptionsMiddleware(BaseHTTPMiddleware):
162
  async def dispatch(self, request, call_next):
163
  response = await call_next(request)
 
747
 
748
  @app.get("/source")
749
  def get_source(auth, sess):
 
 
750
  # Back icon to go back to main page in top left corner
751
  return (
752
  Title("Source code"),
 
761
  style="margin: 10px;",
762
  ),
763
  Div(
764
+ f"""### `main.py`\n### This is the complete source code for this app \n```python\n{SOURCE}\n```""",
765
  cls="marked",
766
  style="margin: 10px;",
767
  ),
 
773
 
774
  @app.get("/about")
775
  def get_about(auth, sess):
 
 
776
  # Strip everything before the FIRST # in the README
777
  stripped_readme = re.sub(
778
+ r"^.*?(?=# FastHTML Vespa frontend)", "", README, flags=re.DOTALL
779
  )
780
 
781
  return (