-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
refactor(server): Add ApiUrl + ServerUrl env + allow usage of https #8579
base: main
Are you sure you want to change the base?
Conversation
Replaced individual environment-based server URL retrievals with a centralized ServerUrl utility. This change simplifies URL management and ensures a consistent approach across different services. Added validation for SSL configurations when using HTTPS.
Removed standalone ServerUrl and integrated with combined ServerUrl/ApiUrl module. Refactored codebase to use ApiUrl for public network accessibility and adjusted corresponding imports.
Renamed utils file for better readability and consistency. Updated all references to the new file name and added unit tests for ServerUrl and ApiUrl functionalities.
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.
PR Summary
This PR adds HTTPS support and introduces separate URL management for server and API endpoints, with SSL certificate configuration and improved URL handling across the application.
- Added
SSL_KEY_PATH
andSSL_CERT_PATH
environment variables in/packages/twenty-server/.env.example
for HTTPS support - Introduced
ServerUrl
andApiUrl
utilities in/packages/twenty-server/src/engine/utils/server-and-api-urls.ts
for centralized URL management - Added validation in
main.ts
to ensure SSL certificates exist when using HTTPS protocol - Refactored services to use
ApiUrl.get()
instead of direct environment variable access for consistent URL handling - Added IPv6 support and protocol detection in URL handling with proper hostname normalization
9 file(s) reviewed, 15 comment(s)
Edit PR Review Bot Settings | Greptile
packages/twenty-server/src/engine/core-modules/environment/environment-variables.ts
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/engine/core-modules/environment/environment-variables.ts
Show resolved
Hide resolved
...server/src/engine/core-modules/workspace-invitation/services/workspace-invitation.service.ts
Show resolved
Hide resolved
Move the reset of ServerUrl and ApiUrl to beforeEach in tests to ensure clean state before each test runs. Update example SSL_KEY_PATH and SSL_CERT_PATH to use relative paths for more portability.
Import the ApiUrl module and set the local URL in the setup function. This ensures the tests have the correct API endpoint configured.
Reordered import statements in `workspace-invitation.service.spec.ts` for improved code organization. This change ensures that dependencies are imported in a more logical sequence.
Included API_URL in self-hosting documentation for public endpoint configuration. This helps developers set up the correct URLs for API interactions in their self-hosted environments.
packages/twenty-server/.env.example
Outdated
@@ -75,3 +75,7 @@ ACCESS_TOKEN_SECRET=replace_me_with_a_random_string_access | |||
# PG_SSL_ALLOW_SELF_SIGNED=true | |||
# SESSION_STORE_SECRET=replace_me_with_a_random_string_session | |||
# ENTERPRISE_KEY=replace_me_with_a_valid_enterprise_key | |||
###### --------------> !!! FOR CHARLES AND FELIX !!! we can create a gist in twenty if you want <--------------------------- |
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.
I think we can store this script in the repo (twenty-server/scripts), you can move instructions there as well (or the dev documentation but I think having a readme in a dedicated scripts/ssl-generation/
folder is fine too 🤔
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.
@AMoreaux let's remove this comment before merging 🙂
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.
My bad it's done
Removed protocol check logic from main.ts and enforced URL validation to require protocol directly in environment variables definition. This ensures consistent and secure URL formats throughout the application.
Add a new Bash script for generating self-signed SSL certificates, including a README with instructions. Supports customizable domain, root certificate name, and validity period, and integrates root certificate into macOS keychain.
SERVER_URL
to define the NestJS instance URLAPI_URL
to set the public URL. Loadbalancer in production. In non-secure environments, it will be the same as theSERVER_URL
SSL
certificate and using https.