From 017b43fe9bcab4437b1ead733b8540f94d932716 Mon Sep 17 00:00:00 2001
From: kaotech-io <221559574+kaotech-io@users.noreply.github.com>
Date: Tue, 7 Oct 2025 20:07:41 +0200
Subject: [PATCH] Add override using environment variable for freestyle.sh
endpoint (#853)
Hi there, I have noticed that the project recently moved to using
freestyle.sh for rendering emails. I am currently self-hosting stack
auth and freestyle.sh does not have a privacy policy as far as I can
see. Therefore, it is not usable in a compliant way.
This PR simply adds an optional environment variable to be able to
override the API endpoint. This way, users can easily opt-out and use a
different implementation to render the mails.
Let me know if this is something you would consider merging and if the
variable should be added in some docs or examples.
----
> [!IMPORTANT]
> Add environment variable `STACK_FREESTYLE_API_ENDPOINT` to override
Freestyle API endpoint in `freestyle.tsx`.
>
> - **Behavior**:
> - Adds environment variable `STACK_FREESTYLE_API_ENDPOINT` to override
Freestyle API endpoint in `Freestyle` class constructor in
`freestyle.tsx`.
> - Defaults to `http://localhost:8122` for development and test
environments if API key is `mock_stack_freestyle_key` and no override is
set.
> - **Imports**:
> - Adds `getEnvVariable` import from
`@stackframe/stack-shared/dist/utils/env` in `freestyle.tsx`.
>
> This description was created by [
](https://www.ellipsis.dev?ref=stack-auth%2Fstack-auth&utm_source=github&utm_medium=referral)
for 58ffd62704c1718e0e45fcba45b8a994059c8831. You can
[customize](https://app.ellipsis.dev/stack-auth/settings/summaries) this
summary. It will automatically update as commits are pushed.
## Summary by CodeRabbit
* **New Features**
* Freestyle service endpoint can be configured via an environment
variable for deployments.
* By default the configured endpoint is used; in development/test, a
mock key causes the client to point to a local default for local
testing.
* **Bug Fixes**
* Using the mock key outside development/test now triggers a validation
error to prevent accidental misuse.
---------
Co-authored-by: Paul Graf
---
apps/backend/src/lib/freestyle.tsx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/apps/backend/src/lib/freestyle.tsx b/apps/backend/src/lib/freestyle.tsx
index d038973c8..150d3e9b6 100644
--- a/apps/backend/src/lib/freestyle.tsx
+++ b/apps/backend/src/lib/freestyle.tsx
@@ -10,7 +10,7 @@ export class Freestyle {
constructor(options: { apiKey?: string } = {}) {
const apiKey = options.apiKey || getEnvVariable("STACK_FREESTYLE_API_KEY");
- let baseUrl = undefined;
+ let baseUrl = getEnvVariable("STACK_FREESTYLE_API_ENDPOINT", "") || undefined;
if (apiKey === "mock_stack_freestyle_key") {
if (!["development", "test"].includes(getNodeEnvironment())) {
throw new StackAssertionError("Mock Freestyle key used in production; please set the STACK_FREESTYLE_API_KEY environment variable.");