Skip to content

Commit a2da4e5

Browse files
authored
frontend: Set frontend hostname as an env var (#283)
* Set frontend hostname as an env var
1 parent 26f19e8 commit a2da4e5

File tree

10 files changed

+30
-4
lines changed

10 files changed

+30
-4
lines changed

.env-template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ USE_COMMUNITY_FEATURES='True'
4545
AUTH_SECRET_KEY=<See auth.guide.md on how to generate a secure one>
4646
# Required for specifying Redirect URI
4747
FRONTEND_HOSTNAME=http://localhost:4000
48+
NEXT_PUBLIC_FRONTEND_HOSTNAME=${FRONTEND_HOSTNAME}
4849

4950
# Google OAuth
5051
GOOGLE_CLIENT_ID=<GOOGLE_CLIENT_ID>

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ services:
6666
# Set environment variables directly in the docker-compose file
6767
environment:
6868
NEXT_PUBLIC_API_HOSTNAME: ${NEXT_PUBLIC_API_HOSTNAME}
69+
NEXT_PUBLIC_FRONTEND_HOSTNAME: ${NEXT_PUBLIC_FRONTEND_HOSTNAME}
6970
restart: always
7071
ports:
7172
- 4000:4000

docker_scripts/env-defaults

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ DB_EXTENSION=${DB_EXTENSION:-}
1414

1515
# Defaults for the toolkit
1616
export NEXT_PUBLIC_API_HOSTNAME=${NEXT_PUBLIC_API_HOSTNAME:-http://localhost:8000}
17+
export FRONTEND_HOSTNAME=${FRONTEND_HOSTNAME:-http://localhost:4000}
18+
export NEXT_PUBLIC_FRONTEND_HOSTNAME=${FRONTEND_HOSTNAME:-http://localhost:4000}
1719
export PYTHON_INTERPRETER_URL=${PYTHON_INTERPRETER_URL:-http://localhost:8080}
1820
export DATABASE_URL=${DATABASE_URL:-postgresql+psycopg2://postgre:postgre@localhost:5432/toolkit}

docs/setup.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ And then retry `poetry --version`
123123
- `COHERE_API_KEY`: If your application will interface with Cohere's API, you will need to supply an API key. Not required if using AWS Sagemaker or Azure.
124124
Sign up at https://dashboard.cohere.com/ to create an API key.
125125
- `NEXT_PUBLIC_API_HOSTNAME`: The backend URL which the frontend will communicate with. Defaults to http://backend:8000 for use with `docker compose`
126+
- `FRONTEND_HOSTNAME`: The URL for the frontend client. Defaults to http://localhost:4000
126127
- `DATABASE_URL`: Your PostgreSQL database connection string for SQLAlchemy, should follow the format `postgresql+psycopg2://USER:PASSWORD@HOST:PORT`.
127128

128129
### AWS Sagemaker

src/backend/cli/main.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class ToolName(StrEnum):
4545
DATABASE_URL_DEFAULT = "postgresql+psycopg2://postgres:postgres@db:5432"
4646
PYTHON_INTERPRETER_URL_DEFAULT = "http://terrarium:8080"
4747
NEXT_PUBLIC_API_HOSTNAME_DEFAULT = "http://localhost:8000"
48+
FRONTEND_HOSTNAME_DEFAULT = "http://localhost:4000"
4849

4950
DOT_ENV_FILE_PATH = ".env"
5051

@@ -82,8 +83,15 @@ def database_url_prompt(secrets):
8283
default=NEXT_PUBLIC_API_HOSTNAME_DEFAULT,
8384
)
8485

86+
print_styled("💾 And now the hostname for the frontend client")
87+
frontend_hostname = inquirer.text(
88+
"Enter your public API Hostname or press enter for default [recommended]",
89+
default=FRONTEND_HOSTNAME_DEFAULT,
90+
)
91+
8592
secrets["DATABASE_URL"] = database_url
8693
secrets["NEXT_PUBLIC_API_HOSTNAME"] = next_public_api_hostname
94+
secrets["FRONTEND_HOSTNAME"] = frontend_hostname
8795

8896

8997
def deployment_prompt(secrets, configs):
@@ -144,6 +152,13 @@ def write_env_file(secrets):
144152
for key, value in secrets.items():
145153
set_key(DOT_ENV_FILE_PATH, key, str(value))
146154

155+
set_key(
156+
DOT_ENV_FILE_PATH,
157+
"NEXT_PUBLIC_FRONTEND_HOSTNAME",
158+
"${FRONTEND_HOSTNAME}",
159+
"never",
160+
)
161+
147162

148163
def select_deployments_prompt(deployments, _):
149164
print_styled("🚀 Let's set up your model deployments.", bcolors.MAGENTA)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# Client
22
NEXT_PUBLIC_API_HOSTNAME=http://localhost:8000
3+
NEXT_PUBLIC_FRONTEND_HOSTNAME=http://localhost:4000
34
NEXT_PUBLIC_HAS_CUSTOM_LOGO=false
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# Client
22
NEXT_PUBLIC_API_HOSTNAME=http://localhost:8000
3+
NEXT_PUBLIC_FRONTEND_HOSTNAME=http://localhost:4000
34
NEXT_PUBLIC_HAS_CUSTOM_LOGO=false

src/interfaces/coral_web/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ pnpm lint
2222

2323
We define environment-specific variables in the `.env.<<ENVIRONMENT>>` files and our current supported environments are: `production`, `stg`/`staging`, `ci`, and `development`. The following are our supported variables:
2424

25-
| Variable | Description |
26-
| ------------------------ | ----------------------------------------------------------- |
27-
| NEXT_PUBLIC_API_HOSTNAME | API hostname that indicates the backend environment to hit. |
25+
| Variable | Description |
26+
| ----------------------------- | ----------------------------------------------------------- |
27+
| NEXT_PUBLIC_API_HOSTNAME | API hostname that indicates the backend environment to hit. |
28+
| NEXT_PUBLIC_FRONTEND_HOSTNAME | The host for the web interface. |
2829

2930
### Resources
3031

src/interfaces/coral_web/src/env.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ export const env = createEnv({
77
},
88
client: {
99
NEXT_PUBLIC_API_HOSTNAME: z.string(),
10+
NEXT_PUBLIC_FRONTEND_HOSTNAME: z.string(),
1011
NEXT_PUBLIC_HAS_CUSTOM_LOGO: z.string().optional().default('false'),
1112
},
1213
runtimeEnv: {
1314
NEXT_PUBLIC_API_HOSTNAME: process.env.NEXT_PUBLIC_API_HOSTNAME,
15+
NEXT_PUBLIC_FRONTEND_HOSTNAME: process.env.NEXT_PUBLIC_FRONTEND_HOSTNAME,
1416
NEXT_PUBLIC_HAS_CUSTOM_LOGO: process.env.NEXT_PUBLIC_HAS_CUSTOM_LOGO,
1517
},
1618
emptyStringAsUndefined: true,

src/interfaces/coral_web/src/hooks/authConfig.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ListAuthStrategy } from '@/cohere-client';
22
import { useServerAuthStrategies } from '@/hooks/authStrategies';
3+
import { env } from '@/env.mjs';
34

45
export const useAuthConfig = (): {
56
loginUrl: string;
@@ -15,6 +16,6 @@ export const useAuthConfig = (): {
1516
registerUrl: '/register',
1617
logoutUrl: '/logout',
1718
loginStrategies: authStrategies,
18-
baseUrl: window.location.href,
19+
baseUrl: env.NEXT_PUBLIC_FRONTEND_HOSTNAME,
1920
};
2021
};

0 commit comments

Comments
 (0)