-
Notifications
You must be signed in to change notification settings - Fork 178
fix(self-host): reduce hosted-only assumptions #409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JustinMissmahl
wants to merge
6
commits into
databuddy-analytics:main
Choose a base branch
from
JustinMissmahl:self_host1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
52102ed
self_host1
712e14c
address https://github.com/databuddy-analytics/Databuddy/pull/409#dis…
9c69aad
address https://github.com/databuddy-analytics/Databuddy/pull/409#dis…
6d702a0
address https://github.com/databuddy-analytics/Databuddy/pull/409#dis…
c16dd5c
help for https://github.com/databuddy-analytics/Databuddy/pull/409#di…
2d35d8a
better CLIENT_APP_ALLOWED_ORIGINS handling with new PUBLIC_API_CORS_M…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| BETTER_AUTH_SECRET="" | ||
| POSTGRES_PASSWORD="" | ||
| CLICKHOUSE_PASSWORD="" | ||
| REDIS_PASSWORD="" | ||
| DATABASE_URL="postgres://databuddy:<POSTGRES_PASSWORD>@postgres:5432/databuddy" | ||
| REDIS_URL="redis://:<REDIS_PASSWORD>@redis:6379" | ||
| CLICKHOUSE_URL="http://default:<CLICKHOUSE_PASSWORD>@clickhouse:8123" | ||
| GITHUB_CLIENT_ID="" | ||
| GITHUB_CLIENT_SECRET="" | ||
| GOOGLE_CLIENT_ID="" | ||
| GOOGLE_CLIENT_SECRET="" | ||
| RESEND_API_KEY="" | ||
|
|
||
| POSTGRES_DB=databuddy | ||
| POSTGRES_USER=databuddy | ||
| POSTGRES_PORT=5432 | ||
|
|
||
| CLICKHOUSE_DB=databuddy_analytics | ||
| CLICKHOUSE_USER=default | ||
| CLICKHOUSE_PORT=8123 | ||
|
|
||
| REDIS_PORT=6379 | ||
|
|
||
| BETTER_AUTH_URL=http://localhost:3100 | ||
| DASHBOARD_URL=http://localhost:3100 | ||
| NEXT_PUBLIC_API_URL=http://localhost:3001 | ||
| NEXT_PUBLIC_APP_URL=http://localhost:3100 | ||
| NEXT_PUBLIC_BASKET_URL=http://localhost:4000 | ||
| NEXT_PUBLIC_SCRIPT_URL=http://localhost:3100/databuddy.js | ||
| NEXT_PUBLIC_BETTER_AUTH_URL=http://localhost:3100 | ||
| AUTH_TRUSTED_ORIGINS=http://localhost:3100,http://localhost:3000,http://localhost:3001 | ||
| CLIENT_APP_ALLOWED_ORIGINS= | ||
| AUTH_COOKIE_DOMAIN= | ||
| APP_URL=http://localhost:3100 | ||
|
|
||
| DASHBOARD_PORT=3100 | ||
| API_PORT=3001 | ||
| BASKET_PORT=4000 | ||
| LINKS_PORT=2500 | ||
|
|
||
| AI_API_KEY=placeholder | ||
| LINKS_ROOT_REDIRECT_URL=http://localhost:3100 | ||
| IMAGE_TAG=edge | ||
| NODE_ENV=production | ||
|
|
||
| NEXT_PUBLIC_DATABUDDY_CLIENT_ID=placeholder | ||
|
|
||
| PUBLIC_API_CORS_MODE=restricted |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ admin | |
|
|
||
| # Local env files | ||
| .env | ||
| .env.prod | ||
| .mcp.json | ||
| .env.local | ||
| .env.development.local | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import { | ||
| getClientAppAllowedOrigins, | ||
| normalizeOrigin, | ||
| } from "@databuddy/shared/utils/origins"; | ||
|
|
||
| const DATABUDDY_DOMAIN_REGEX = /(?:^|\.)databuddy\.cc$/; | ||
|
|
||
| export function getAllowedCorsOrigins(): Array<string | RegExp> { | ||
| const defaults = [ | ||
| process.env.BETTER_AUTH_URL, | ||
| process.env.NEXT_PUBLIC_APP_URL, | ||
| process.env.NEXT_PUBLIC_API_URL, | ||
| process.env.DASHBOARD_URL, | ||
| process.env.APP_URL, | ||
| process.env.NODE_ENV === "development" | ||
| ? "http://localhost:3000" | ||
| : undefined, | ||
| process.env.NODE_ENV === "development" | ||
| ? "http://localhost:3100" | ||
| : undefined, | ||
| process.env.NODE_ENV === "development" | ||
| ? "http://localhost:3001" | ||
| : undefined, | ||
| ] | ||
| .filter((value): value is string => Boolean(value)) | ||
| .map((value) => normalizeOrigin(value)) | ||
| .filter((value): value is string => Boolean(value)); | ||
|
|
||
| const extraOrigins = getClientAppAllowedOrigins(); | ||
| const authTrustedOrigins = (process.env.AUTH_TRUSTED_ORIGINS ?? "") | ||
| .split(",") | ||
| .map((origin) => normalizeOrigin(origin)) | ||
| .filter((origin): origin is string => Boolean(origin)); | ||
|
|
||
| return [ | ||
| DATABUDDY_DOMAIN_REGEX, | ||
| ...new Set([...defaults, ...authTrustedOrigins, ...extraOrigins]), | ||
| ]; | ||
| } | ||
|
|
||
| export function getPublicCorsOrigins(): true | Array<string | RegExp> { | ||
| return process.env.PUBLIC_API_CORS_MODE === "restricted" | ||
| ? getAllowedCorsOrigins() | ||
| : true; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NEXT_PUBLIC_API_URLincluded as a CORS-allowed origin for the API itselfCORS allowed origins represent browsers/apps that may issue cross-origin requests to the API, not the API itself. Including
NEXT_PUBLIC_API_URL(e.g.http://localhost:3001) means the API treats its own URL as a permitted front-end origin, which is a no-op in practice but adds unnecessary noise. Consider removing it from thedefaultsarray.