Add override using environment variable for freestyle.sh endpoint#853
Add override using environment variable for freestyle.sh endpoint#853BilalG1 merged 11 commits intohexclave:devfrom
Conversation
|
@pgr4567 is attempting to deploy a commit to the Stack Team on Vercel. A member of the Team first needs to authorize it. |
WalkthroughReads STACK_FREESTYLE_API_ENDPOINT via getEnvVariable to set Freestyle baseUrl; if unset and apiKey equals the mock key, asserts NODE_ENV is development/test and forces baseUrl to http://localhost:8122. No public API changes. (≤50 words) Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Caller
participant FreestyleConfig as Freestyle Config
participant Env as Environment
Caller->>FreestyleConfig: Initialize Freestyle client (apiKey)
FreestyleConfig->>Env: getEnvVariable("STACK_FREESTYLE_API_ENDPOINT")
alt Env var is set (non-empty)
FreestyleConfig-->>Caller: Use env-provided baseUrl
else Env var unset/empty
FreestyleConfig->>Env: getNodeEnvironment()
alt apiKey == "mock_stack_freestyle_key" AND NODE_ENV in (development,test)
FreestyleConfig-->>Caller: Set baseUrl = http://localhost:8122
else apiKey == "mock_stack_freestyle_key" AND NODE_ENV not allowed
FreestyleConfig-->>Caller: Throw StackAssertionError
else
FreestyleConfig-->>Caller: Leave baseUrl undefined (default)
end
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Pre-merge checks (2 passed, 1 warning)❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
Poem
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).Please share your feedback with us on this Discord post. 📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Greptile Summary
This PR introduces a new environment variable STACK_FREESTYLE_API_ENDPOINT that allows self-hosting users to override the default freestyle.sh API endpoint used for email rendering. The change modifies the apps/backend/src/lib/freestyle.tsx file to check for this environment variable first before falling back to the existing logic.
The implementation uses the existing getEnvVariable() utility to read the optional environment variable. When STACK_FREESTYLE_API_ENDPOINT is set, it takes precedence over the default behavior. The existing development/test logic remains intact - if the environment is development or test AND the API key is the mock key AND no custom endpoint is provided, it still falls back to http://localhost:8122.
This change addresses a compliance concern where the default freestyle.sh service lacks a privacy policy, making it unsuitable for users who need GDPR or other regulatory compliance. The modification maintains full backward compatibility while providing flexibility for self-hosted deployments to use alternative email rendering services.
Confidence score: 4/5
- This PR is safe to merge with minimal risk to existing functionality
- Score reflects simple, well-contained change with clear backward compatibility
- No files require special attention as the change is straightforward and isolated
1 file reviewed, no comments
Review by RecurseML🔍 Review performed on 933c60d..58ffd62 ✨ No bugs found, your code is sparkling clean ✅ Files analyzed, no issues (1)• |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
apps/backend/src/lib/freestyle.tsx (1)
2-2: Import is fine, but confirm server-only usage and document the new env varUsing
getEnvVariablein backend code is appropriate; just ensure this file never runs on the client, as that utility intentionally throws in browser-like environments. Also, since this introduces a new configuration surface, please documentSTACK_FREESTYLE_API_ENDPOINT(purpose, example value, and when the localhost fallback applies) in self-hosting docs and any.env.examplefiles.I can draft the docs snippet and update
.env.examplein a follow-up if you want.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
apps/backend/src/lib/freestyle.tsx(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
apps/backend/src/lib/freestyle.tsx (1)
packages/stack-shared/src/utils/env.tsx (2)
getEnvVariable(16-58)getNodeEnvironment(65-67)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Security Check
|
@kaotech-io this looks fine. Can you merge in latest dev and then we can merge |
…/stack-auth into freestyle-api-endpoint-env-var
|
@BilalG1 sure, i just very recently merged in develop again |
|
@BilalG1 anything else you would need from me to get this merged? |
|
When is this pull request getting merged? I need this to be able to run freestyle locally. |
|
Yeah, I have honestly given up at this point |
|
hey, sorry for the delay in merging @kaotech-io. I just fixed my github notifications so next time I won't miss this |
|
No problem, thank you! |
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_ENDPOINTto override Freestyle API endpoint infreestyle.tsx.STACK_FREESTYLE_API_ENDPOINTto override Freestyle API endpoint inFreestyleclass constructor infreestyle.tsx.http://localhost:8122for development and test environments if API key ismock_stack_freestyle_keyand no override is set.getEnvVariableimport from@stackframe/stack-shared/dist/utils/envinfreestyle.tsx.This description was created by
for 58ffd62. You can customize this summary. It will automatically update as commits are pushed.
Summary by CodeRabbit