Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions bats_ai/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,17 @@
# Django staticfiles auto-creates any intermediate directories, but do so here to prevent warnings.
STATIC_ROOT.mkdir(exist_ok=True)

# Can be set to mount all URLs at a subpath
BATAI_URL_PATH: str = env.str('DJANGO_BATAI_URL_PATH', default='').strip('/')

BATAI_NABAT_API_URL: str = env.str(
'DJANGO_BATAI_NABAT_API_URL', default='https://api.sciencebase.gov/nabat-graphql/graphql'
)

# Django's docs suggest that STATIC_URL should be a relative path,
# for convenience serving a site on a subpath.
STATIC_URL = f'/{BATAI_URL_PATH}/static/' if BATAI_URL_PATH else '/static/'
LOGIN_URL = f'/{BATAI_URL_PATH}/accounts/login/' if BATAI_URL_PATH else '/accounts/login/'
STATIC_URL = 'static/'

# Make Django and Allauth redirects consistent, but both may be changed.
LOGIN_REDIRECT_URL = f'/{BATAI_URL_PATH}'
ACCOUNT_LOGOUT_REDIRECT_URL = f'/{BATAI_URL_PATH}'
LOGIN_REDIRECT_URL = '/'
ACCOUNT_LOGOUT_REDIRECT_URL = '/'

CORS_ALLOWED_ORIGINS: list[str] = env.list('DJANGO_CORS_ALLOWED_ORIGINS', cast=str, default=[])
CORS_ALLOWED_ORIGIN_REGEXES: list[str] = env.list(
Expand Down
8 changes: 8 additions & 0 deletions bats_ai/settings/nabat_production.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,11 @@
CORS_ALLOWED_ORIGINS = [f'https://{BASE_HOST}', f'https://{BASE_HOST}']

SECURE_SSL_REDIRECT = False

# Can be set to mount all URLs at a subpath
_proxy_subpath: str | None = env.str('DJANGO_BATAI_URL_PATH', default=None)
if _proxy_subpath:
_proxy_subpath = f'/{_proxy_subpath.strip("/")}'
FORCE_SCRIPT_NAME = _proxy_subpath
# Work around https://code.djangoproject.com/ticket/36653
STORAGES['staticfiles'].setdefault('OPTIONS', {})['base_url'] = f'{_proxy_subpath}/{STATIC_URL}'
9 changes: 1 addition & 8 deletions bats_ai/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,14 @@

from .api import api

base_urlpatterns = [
urlpatterns = [
path('accounts/', include('allauth.urls')),
path('oauth/', include('oauth2_provider.urls')),
path('admin/', admin.site.urls),
path('api/v1/s3-upload/', include('s3_file_field.urls')),
path('api/v1/', api.urls),
]


# Support mounting within a sub-path
if settings.BATAI_URL_PATH:
urlpatterns = [path(f'{settings.BATAI_URL_PATH}/', include(base_urlpatterns))]
else:
urlpatterns = base_urlpatterns

if settings.DEBUG:
import debug_toolbar.toolbar

Expand Down
Loading