Use KHOJ_HOST env var to set allowed/trusted domains to host Khoj

Allows hosting Khoj behind other, non "khoj.dev" domains
This commit is contained in:
Debanjum Singh Solanky 2023-11-21 13:11:45 -08:00
parent 90d463c12a
commit 76d041f633

View file

@ -26,13 +26,13 @@ SECRET_KEY = os.getenv("KHOJ_DJANGO_SECRET_KEY")
# SECURITY WARNING: don't run with debug turned on in production! # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.getenv("KHOJ_DEBUG") == "True" DEBUG = os.getenv("KHOJ_DEBUG") == "True"
ALLOWED_HOSTS = [".khoj.dev", "localhost", "127.0.0.1", "[::1]", "beta.khoj.dev"] # All Subdomains of KHOJ_DOMAIN are trusted
KHOJ_DOMAIN = os.getenv("KHOJ_DOMAIN", "khoj.dev")
ALLOWED_HOSTS = [f".{KHOJ_DOMAIN}", "localhost", "127.0.0.1", "[::1]"]
CSRF_TRUSTED_ORIGINS = [ CSRF_TRUSTED_ORIGINS = [
"https://app.khoj.dev", f"https://*.{KHOJ_DOMAIN}",
"https://beta.khoj.dev", f"https://{KHOJ_DOMAIN}",
"https://khoj.dev",
"https://*.khoj.dev",
] ]
COOKIE_SAMESITE = "None" COOKIE_SAMESITE = "None"
@ -40,8 +40,8 @@ if DEBUG:
SESSION_COOKIE_DOMAIN = "localhost" SESSION_COOKIE_DOMAIN = "localhost"
CSRF_COOKIE_DOMAIN = "localhost" CSRF_COOKIE_DOMAIN = "localhost"
else: else:
SESSION_COOKIE_DOMAIN = "khoj.dev" SESSION_COOKIE_DOMAIN = KHOJ_DOMAIN
CSRF_COOKIE_DOMAIN = "khoj.dev" CSRF_COOKIE_DOMAIN = KHOJ_DOMAIN
SESSION_COOKIE_SECURE = True SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True CSRF_COOKIE_SECURE = True