-
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
Open
AMoreaux
wants to merge
10
commits into
twentyhq:main
Choose a base branch
from
AMoreaux:feat/allow-to-use-ssl
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 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
450d137
refactor(core): centralize SERVER_URL logic + allow ssl on server
AMoreaux 398364d
refactor: consolidate ServerUrl and ApiUrl handling
AMoreaux 4fbaaac
refactor: rename serverAndApiUrl to server-and-api-urls
AMoreaux 8a88f40
fix(server-setup): Adjust test hooks and SSL config paths
AMoreaux 886c6f2
test: Adjust WorkspaceInvitationService tests to set ApiUrl
AMoreaux 7ef1c73
[test] Reorder import statements
AMoreaux a933d31
feat(self-hosting): Add API_URL to environment variables
AMoreaux 8b40561
fix(server): enforce protocol in environment URLs
AMoreaux 8cf6502
feat(ssl-generation): Add SSL generation script
AMoreaux 79a8da2
chore(): remove comment
AMoreaux 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 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 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 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 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 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 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 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
56 changes: 56 additions & 0 deletions
56
packages/twenty-server/src/engine/utils/__tests__/server-and-api-urls.spec.ts
This file contains 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,56 @@ | ||
import { ServerUrl, ApiUrl } from 'src/engine/utils/server-and-api-urls'; | ||
|
||
describe('ServerUrl', () => { | ||
afterEach(() => { | ||
// Reset the serverUrl after each test | ||
ServerUrl.set(''); | ||
}); | ||
|
||
test('should throw error when getting uninitialized ServerUrl', () => { | ||
expect(() => ServerUrl.get()).toThrow( | ||
'ServerUrl is not initialized. Call set() first.', | ||
); | ||
}); | ||
|
||
test('should set and get ServerUrl correctly', () => { | ||
const url = 'http://localhost:3000'; | ||
|
||
ServerUrl.set(url); | ||
expect(ServerUrl.get()).toBe(url); | ||
}); | ||
}); | ||
|
||
describe('ApiUrl', () => { | ||
beforeEach(() => { | ||
// Reset the ServerUrl and apiUrl before each test | ||
ServerUrl.set(''); | ||
ApiUrl.set(''); | ||
}); | ||
|
||
test('should throw error when getting uninitialized ApiUrl', () => { | ||
expect(() => ApiUrl.get()).toThrow( | ||
'apiUrl is not initialized. Call set() first.', | ||
); | ||
}); | ||
|
||
test('should throw error when setting ApiUrl without initializing ServerUrl', () => { | ||
expect(() => ApiUrl.set()).toThrow( | ||
'ServerUrl is not initialized. Call set() first.', | ||
); | ||
}); | ||
|
||
test('should set and get ApiUrl correctly', () => { | ||
const apiUrl = 'http://api.example.com'; | ||
|
||
ApiUrl.set(apiUrl); | ||
expect(ApiUrl.get()).toBe(apiUrl); | ||
}); | ||
|
||
test('should set ApiUrl to ServerUrl value if no argument is passed', () => { | ||
const serverUrl = 'http://localhost:3000'; | ||
|
||
ServerUrl.set(serverUrl); | ||
ApiUrl.set(); // Set without argument, it should use ServerUrl.get() | ||
expect(ApiUrl.get()).toBe(serverUrl); | ||
}); | ||
}); |
37 changes: 37 additions & 0 deletions
37
packages/twenty-server/src/engine/utils/server-and-api-urls.ts
This file contains 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,37 @@ | ||
// The url of the Server, should be exposed in a private network | ||
const ServerUrl = (() => { | ||
let serverUrl = ''; | ||
|
||
return { | ||
get: () => { | ||
if (serverUrl === '') { | ||
throw new Error('ServerUrl is not initialized. Call set() first.'); | ||
} | ||
|
||
return serverUrl; | ||
}, | ||
set: (url: string) => { | ||
serverUrl = url; | ||
}, | ||
AMoreaux marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
})(); | ||
|
||
// The url of the API callable from the public network | ||
const ApiUrl = (() => { | ||
let apiUrl = ''; | ||
|
||
return { | ||
get: () => { | ||
if (apiUrl === '') { | ||
throw new Error('apiUrl is not initialized. Call set() first.'); | ||
} | ||
|
||
return apiUrl; | ||
}, | ||
set: (url: string = ServerUrl.get()) => { | ||
apiUrl = url; | ||
}, | ||
AMoreaux marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
})(); | ||
|
||
export { ServerUrl, ApiUrl }; |
This file contains 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 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.
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