Skip to content

Add override using environment variable for freestyle.sh endpoint#853

Merged
BilalG1 merged 11 commits intohexclave:devfrom
kaotechio:freestyle-api-endpoint-env-var
Oct 7, 2025
Merged

Add override using environment variable for freestyle.sh endpoint#853
BilalG1 merged 11 commits intohexclave:devfrom
kaotechio:freestyle-api-endpoint-env-var

Conversation

@kaotech-io
Copy link
Copy Markdown
Contributor

@kaotech-io kaotech-io commented Aug 19, 2025

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 Ellipsis for 58ffd62. You can customize 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.

@vercel
Copy link
Copy Markdown

vercel Bot commented Aug 19, 2025

@pgr4567 is attempting to deploy a commit to the Stack Team on Vercel.

A member of the Team first needs to authorize it.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Aug 19, 2025

CLA assistant check
All committers have signed the CLA.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Aug 19, 2025

Walkthrough

Reads 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

Cohort / File(s) Summary
Freestyle base URL configuration
apps/backend/src/lib/freestyle.tsx
Added getEnvVariable import; initialize baseUrl from STACK_FREESTYLE_API_ENDPOINT. When apiKey === "mock_stack_freestyle_key", require NODE_ENV be development or test (throw otherwise) and set baseUrl to http://localhost:8122, overriding the env var fallback logic.

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
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • freestyle api key in docs #836 — touches Freestyle service configuration and STACK_FREESTYLE_API_KEY/docs; closely related to endpoint and mock behavior changes.

Suggested reviewers

  • N2D4

Pre-merge checks (2 passed, 1 warning)

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The current pull request description is missing the required boilerplate comment that reminds contributors to read the CONTRIBUTING.md guidelines and does not follow a structured template with clearly defined sections, instead presenting a free-form narrative and an auto-generated summary without the repository’s standard headings. Please add the provided template comment linking to CONTRIBUTING.md at the top of the description and reorganize the content into the repository’s standard sections (for example, Summary, Motivation, Implementation, and Testing) to align with the required PR template.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly describes adding an override for the freestyle.sh endpoint using an environment variable, which directly reflects the main change introduced by this pull request in a clear and concise manner.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.

Poem

A rabbit hops through env and code,
I sniff a var and pick a road.
If endpoint sleeps, and mocks appear,
localhost I hold quite near.
Dev-time hops, config aglow—freestyle bound where carrots grow. 🥕

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.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

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 details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d378eee and 48c4a73.

📒 Files selected for processing (1)
  • apps/backend/src/lib/freestyle.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/backend/src/lib/freestyle.tsx
⏰ 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
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Edit Code Review Bot Settings | Greptile

@recurseml
Copy link
Copy Markdown

recurseml Bot commented Aug 19, 2025

Review by RecurseML

🔍 Review performed on 933c60d..58ffd62

✨ No bugs found, your code is sparkling clean

✅ Files analyzed, no issues (1)

apps/backend/src/lib/freestyle.tsx

Need help? Join our Discord

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 var

Using getEnvVariable in 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 document STACK_FREESTYLE_API_ENDPOINT (purpose, example value, and when the localhost fallback applies) in self-hosting docs and any .env.example files.

I can draft the docs snippet and update .env.example in 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.

📥 Commits

Reviewing files that changed from the base of the PR and between 933c60d and 58ffd62.

📒 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

Comment thread apps/backend/src/lib/freestyle.tsx Outdated
@BilalG1 BilalG1 assigned kaotech-io and unassigned BilalG1 Aug 26, 2025
@BilalG1
Copy link
Copy Markdown
Collaborator

BilalG1 commented Aug 26, 2025

@kaotech-io this looks fine. Can you merge in latest dev and then we can merge

@kaotech-io
Copy link
Copy Markdown
Contributor Author

@BilalG1 sure, i just very recently merged in develop again

@kaotech-io
Copy link
Copy Markdown
Contributor Author

@BilalG1 anything else you would need from me to get this merged?

@kaotech-io kaotech-io requested a review from BilalG1 September 17, 2025 23:47
@hkaiser25
Copy link
Copy Markdown

When is this pull request getting merged? I need this to be able to run freestyle locally.

@kaotech-io
Copy link
Copy Markdown
Contributor Author

Yeah, I have honestly given up at this point

@BilalG1 BilalG1 merged commit 017b43f into hexclave:dev Oct 7, 2025
4 of 8 checks passed
@BilalG1
Copy link
Copy Markdown
Collaborator

BilalG1 commented Oct 7, 2025

hey, sorry for the delay in merging @kaotech-io.

I just fixed my github notifications so next time I won't miss this

@kaotech-io
Copy link
Copy Markdown
Contributor Author

No problem, thank you!

@coderabbitai coderabbitai Bot mentioned this pull request Oct 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants