Skip to content

Commit

Permalink
basic auth
Browse files Browse the repository at this point in the history
  • Loading branch information
phact committed Sep 13, 2024
1 parent ae261dd commit 0857e41
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 3 additions & 1 deletion code_assistant/constants/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
GENERATED_APPS_DIR = os.getcwd() + "/" + os.getenv('CA_GENERATED_APPS_DIR', 'generated_apps')
MODEL = os.getenv('CA_MODEL', 'gpt-4o-2024-08-06')
#MODEL = os.getenv('CA_MODEL', 'openai/o1-preview')
#MODEL = os.getenv('CA_MODEL', 'claude-3-5-sonnet-20240620')
#MODEL = os.getenv('CA_MODEL', 'claude-3-5-sonnet-20240620')
USER = os.getenv('CA_USER')
PASSWORD = os.getenv('CA_PASSWORD')
12 changes: 9 additions & 3 deletions code_assistant/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
from code_assistant.constants.css_text import css_text
from code_assistant.constants.post_message_listener_src import post_message_listener_src
from code_assistant.util.file_util import get_mount_from_project
from code_assistant.constants.config import GENERATED_APPS_DIR
from code_assistant.constants.config import GENERATED_APPS_DIR
from code_assistant.constants.config import GENERATED_APPS_DIR, USER, PASSWORD

from importlib.resources import files

Expand Down Expand Up @@ -49,7 +48,14 @@

iframe_post_message_script = Script(post_message_listener_src, type="module")

app, rt = fast_app(hdrs=(tlink, dlink, css, scrollScript, plink, iframe_post_message_script), routes=app_routes)

middleware = []
if USER is not None and PASSWORD is not None:
print("Setting up basic auth")
auth = user_pwd_auth({USER: PASSWORD}, skip=[r'/favicon\.ico', r'/static/.*', r'.*\.css'])
middleware.append(auth)

app, rt = fast_app(hdrs=(tlink, dlink, css, scrollScript, plink, iframe_post_message_script), routes=app_routes, middleware=middleware)

#setup_toasts(app) work around toast bug until fasthtml 5.2 ships
app.hdrs += (Style(toast_css), Script(toast_js, type="module"))
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "code-assistant"
version = "0.1.0"
version = "0.1.1"
description = "A FastHTML app that builds FastHTML apps"
authors = [{ name = "phact", email = "[email protected]" }]
readme = "README.md"
Expand Down

0 comments on commit 0857e41

Please sign in to comment.