mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-27 17:35:07 +01:00
Pass multiple allowed Khoj domains via KHOJ_DOMAIN env var
To add multiple allowed Khoj domains pass them as a comma separated list of domains via the KHOJ_DOMAIN environment variable Resolve comment in issue #662
This commit is contained in:
parent
4daf16e5f9
commit
d8a5a01cea
1 changed files with 18 additions and 11 deletions
|
@ -3,6 +3,7 @@
|
|||
"""
|
||||
|
||||
from contextlib import redirect_stdout
|
||||
import itertools
|
||||
import logging
|
||||
import io
|
||||
import os
|
||||
|
@ -66,19 +67,25 @@ else:
|
|||
django_app = get_asgi_application()
|
||||
|
||||
# Add CORS middleware
|
||||
KHOJ_DOMAIN = os.getenv("KHOJ_DOMAIN", "app.khoj.dev")
|
||||
KHOJ_DOMAIN = os.getenv("KHOJ_DOMAIN", "app.khoj.dev").split(",")
|
||||
scheme = "https" if not is_env_var_true("KHOJ_NO_HTTPS") else "http"
|
||||
custom_origins = list(
|
||||
itertools.chain.from_iterable(
|
||||
[[f"{scheme}://{domain.strip()}", f"{scheme}://{domain.strip()}:*"] for domain in KHOJ_DOMAIN]
|
||||
)
|
||||
)
|
||||
default_origins = [
|
||||
"app://obsidian.md", # To allow access from Obsidian desktop app
|
||||
"capacitor://localhost", # To allow access from Obsidian iOS app using Capacitor.JS
|
||||
"http://localhost", # To allow access from Obsidian Android app
|
||||
"http://localhost:*", # To allow access from localhost
|
||||
"http://127.0.0.1:*", # To allow access from localhost
|
||||
"app://khoj.dev", # To allow access from Khoj desktop app
|
||||
]
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=[
|
||||
"app://obsidian.md",
|
||||
"capacitor://localhost", # To allow access from Obsidian iOS app using Capacitor.JS
|
||||
"http://localhost", # To allow access from Obsidian Android app
|
||||
"http://localhost:*",
|
||||
"http://127.0.0.1:*",
|
||||
f"https://{KHOJ_DOMAIN}" if not is_env_var_true("KHOJ_NO_HTTPS") else f"http://{KHOJ_DOMAIN}",
|
||||
f"https://{KHOJ_DOMAIN}:*" if not is_env_var_true("KHOJ_NO_HTTPS") else f"http://{KHOJ_DOMAIN}:*",
|
||||
"app://khoj.dev",
|
||||
],
|
||||
allow_origins=default_origins + custom_origins,
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
|
|
Loading…
Reference in a new issue