Django Hosts
The Smarter Framework supports multiple hosts using the django-hosts package.
This module defines the complete set of host patterns for the Smarter Framework, organized by logical group.
Web Console Hosts
Host |
Description |
|---|---|
localhost:9357 |
For local development via http://localhost:9357/ |
127.0.0.1:9357 |
For local development via http://127.0.0.1:9357/ |
platform.example.com |
Main production platform console. |
alpha.platform.example.com |
Alpha environment for the platform console. |
beta.platform.example.com |
Beta environment for the platform console. |
next.platform.example.com |
Next environment for the platform console. |
API Subdomain Hosts
Host |
Description |
|---|---|
api.localhost:9357 |
Local API endpoint for http://api.localhost:9357/ |
api.127.0.0.1:9357 |
Local API endpoint for http://api.127.0.0.1:9357/ |
api.example.com |
Main production API endpoint. |
alpha.api.example.com |
Alpha environment for the API. |
beta.api.example.com |
Beta environment for the API. |
next.api.example.com |
Next environment for the API. |
Named LLMClient Hosts
Host |
Description |
|---|---|
<llmclient_name>.<account_number>.api.example.com |
Deployed named llmclient on production API. |
<llmclient_name>.<account_number>.alpha.api.example.com |
Deployed named llmclient on alpha API. |
<llmclient_name>.<account_number>.beta.api.example.com |
Deployed named llmclient on beta API. |
<llmclient_name>.<account_number>.next.api.example.com |
Deployed named llmclient on next API. |
Each host pattern is mapped to the appropriate Django URL configuration for the console, API, or llmclient endpoints, and supports multiple environments for development, staging, and production.
1import re
2
3from django_hosts import host, patterns
4
5from smarter.common.conf import smarter_settings
6from smarter.common.const import SmarterEnvironments
7from smarter.urls import api as smarter_api_urls
8from smarter.urls import console as smarter_console_urls
9from smarter.urls import llmclients as smarter_llmclients_urls
10
11API_DOMAIN = re.escape(smarter_settings.root_api_domain)
12"""The root api domain, e.g. api.platform.example.com, as a regular expression.
13
14Deployed LLMClients are its subdomains, e.g. stackademy-sql.3141-5926-5359.api.platform.example.com,
15the same domain that :attr:`LLMClient.default_host` is built from. It includes the platform subdomain.
16"""
17
18host_patterns = patterns(
19 "",
20 # -------------------------------------------------------------------------
21 # web console
22 # -------------------------------------------------------------------------
23 host(r"localhost:9357", smarter_console_urls, name="localhost"), # for http://localhost:9357/
24 host(r"127.0.0.1:9357", smarter_console_urls, name="127001"), # for http://127.0.0.1:9357/
25 host(
26 rf"{smarter_settings.platform_subdomain}.{smarter_settings.platform_root_domain}",
27 smarter_console_urls,
28 name=smarter_settings.platform_subdomain,
29 ), # for https://platform.example.com/
30 host(
31 rf"{SmarterEnvironments.ALPHA}.{smarter_settings.platform_subdomain}.{smarter_settings.platform_root_domain}",
32 smarter_console_urls,
33 name=f"{SmarterEnvironments.ALPHA}_{smarter_settings.platform_subdomain}",
34 ), # for https://alpha.platform.example.com/
35 host(
36 rf"{SmarterEnvironments.BETA}.{smarter_settings.platform_subdomain}.{smarter_settings.platform_root_domain}",
37 smarter_console_urls,
38 name=f"{SmarterEnvironments.BETA}_{smarter_settings.platform_subdomain}",
39 ), # for https://beta.platform.example.com/
40 host(
41 rf"{SmarterEnvironments.NEXT}.{smarter_settings.platform_subdomain}.{smarter_settings.platform_root_domain}",
42 smarter_console_urls,
43 name=f"{SmarterEnvironments.NEXT}_{smarter_settings.platform_subdomain}",
44 ), # for https://next.platform.example.com/
45 # -------------------------------------------------------------------------
46 # API subdomains
47 # -------------------------------------------------------------------------
48 host(r"api.localhost:9357", smarter_api_urls, name="api_localhost"), # for http://api.localhost:9357/
49 host(r"api.127.0.0.1:9357", smarter_api_urls, name="api_127001"), # for http://api.127.0.0.1:9357/
50 host(
51 rf"{smarter_settings.api_subdomain}.{smarter_settings.platform_root_domain}",
52 smarter_api_urls,
53 name=smarter_settings.api_subdomain,
54 ), # for https://api.platform.example.com/
55 host(
56 rf"{SmarterEnvironments.ALPHA}.{smarter_settings.api_subdomain}.{smarter_settings.platform_root_domain}",
57 smarter_api_urls,
58 name=f"{SmarterEnvironments.ALPHA}_{smarter_settings.api_subdomain}",
59 ), # for https://alpha.api.platform.example.com/
60 host(
61 rf"{SmarterEnvironments.BETA}.{smarter_settings.api_subdomain}.{smarter_settings.platform_root_domain}",
62 smarter_api_urls,
63 name=f"{SmarterEnvironments.BETA}_{smarter_settings.api_subdomain}",
64 ), # for https://beta.api.platform.example.com/
65 host(
66 rf"{SmarterEnvironments.NEXT}.{smarter_settings.api_subdomain}.{smarter_settings.platform_root_domain}",
67 smarter_api_urls,
68 name=f"{SmarterEnvironments.NEXT}_{smarter_settings.api_subdomain}",
69 ), # for https://next.api.platform.example.com/
70 # -------------------------------------------------------------------------
71 # Deployed named LLMClients
72 # eg https://education.3141-5926-5359.alpha.api.example.com/
73 # -------------------------------------------------------------------------
74 host(
75 rf"(?P<llmclient_name>[\w\-]+)\.(?P<account_number>\d{{4}}-\d{{4}}-\d{{4}})\.{API_DOMAIN}",
76 smarter_llmclients_urls,
77 name="llmclient_named_api",
78 ), # for https://<llmclient_name>.<account_number>.api.platform.example.com/
79 host(
80 rf"(?P<llmclient_name>[\w\-]+)\.(?P<account_number>\d{{4}}-\d{{4}}-\d{{4}})\.{re.escape(SmarterEnvironments.ALPHA)}\.{API_DOMAIN}",
81 smarter_llmclients_urls,
82 name=f"llmclient_named_{SmarterEnvironments.ALPHA}_api",
83 ), # for https://<llmclient_name>.<account_number>.alpha.api.platform.example.com/
84 host(
85 rf"(?P<llmclient_name>[\w\-]+)\.(?P<account_number>\d{{4}}-\d{{4}}-\d{{4}})\.{re.escape(SmarterEnvironments.BETA)}\.{API_DOMAIN}",
86 smarter_llmclients_urls,
87 name=f"llmclient_named_{SmarterEnvironments.BETA}_api",
88 ), # for https://<llmclient_name>.<account_number>.beta.api.platform.example.com/
89 host(
90 rf"(?P<llmclient_name>[\w\-]+)\.(?P<account_number>\d{{4}}-\d{{4}}-\d{{4}})\.{re.escape(SmarterEnvironments.NEXT)}\.{API_DOMAIN}",
91 smarter_llmclients_urls,
92 name=f"llmclient_named_{SmarterEnvironments.NEXT}_api",
93 ), # for https://<llmclient_name>.<account_number>.next.api.platform.example.com/
94)
95
96__all__ = ["host_patterns"]