-
Notifications
You must be signed in to change notification settings - Fork 9k
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
fix(core): Refactor how base urls are defined to make urls consistent across the backend #6713
Conversation
Great PR! Please pay attention to the following items before merging: Files matching
Files matching
Files matching
Make sure to check off this list before asking for review. |
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #6713 +/- ##
=======================================
Coverage 33.59% 33.60%
=======================================
Files 3401 3402 +1
Lines 207699 207722 +23
Branches 22467 22469 +2
=======================================
+ Hits 69781 69802 +21
- Misses 136771 136772 +1
- Partials 1147 1148 +1
☔ View full report in Codecov by Sentry. |
workflowData.id | ||
}/executions/${executionId}`; | ||
const { editorBaseUrl } = Container.get(URLService); | ||
pastExecutionUrl = `${editorBaseUrl}workflow/${workflowData.id}/executions/${executionId}`; |
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.
changed this to use editor url instead of webhook url, as i believe that is the correct url.
baseUrl: { | ||
format: String, | ||
default: '', | ||
env: 'N8N_BASE_URL', |
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.
added a new env variable, as WEBHOOK_URL
was never meant to be used for non webhook urls (even though in some please it incorrectly is used that way).
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.
The problem with this new variable is that users were supposed to set up n8n using N8N_HOST
, N8N_PATH
and N8N_PORT
@@ -1,15 +1,15 @@ | |||
export class SamlUrls { | |||
static readonly samlRESTRoot = '/rest/sso/saml'; |
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.
a hardcoded /rest
somehow managed to sneak past reviews.
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.
Good catch
@@ -138,10 +138,10 @@ export class SamlController { | |||
if (isSamlLicensedAndEnabled()) { | |||
await issueCookie(res, loginResult.authenticatedUser); | |||
if (loginResult.onboardingRequired) { | |||
return res.redirect(getInstanceBaseUrl() + SamlUrls.samlOnboarding); | |||
return res.redirect(this.urlService.editorBaseUrl + SamlUrls.samlOnboarding); |
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.
this should be using editorBaseUrl
so that these urls work with --tunnel
, and also when someone is overriding the base url.
@@ -138,14 +141,14 @@ export class SamlService { | |||
|
|||
private getRedirectLoginRequestUrl(relayState?: string): BindingContext { | |||
const sp = this.getServiceProviderInstance(); | |||
sp.entitySetting.relayState = relayState ?? getInstanceBaseUrl(); | |||
sp.entitySetting.relayState = relayState ?? this.urlService.editorBaseUrl; |
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.
same here. I'm wondering if we should add createBackendUrl
and createFrontendUrl
methods in URLService
, so that people are forced to declare if the generated url is meant to be handled by the frontend, or the backend.
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.
That's a fair point, maybe in the future we have these services running in separate places (rest API and FE). I'm afraid this would make the PR larger, useless at this time and harder to test. For now I think it's ok to assume that editor and rest api are always on the same host (as they actually are)
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.
Thanks for taking this on!
From a quick test, running packages/cli/bin/n8n start --tunnel
fails to open in browser, after a while ends up with 504 Gateway Time-out
format: String, | ||
default: '', | ||
env: 'WEBHOOK_URL', | ||
doc: 'Used to manually provide the Webhook URL when running n8n behind a reverse proxy.', |
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.
Let's specify in the description what these default to?
webhook: string; | ||
oauth1Callback: string; | ||
oauth2Callback: string; | ||
}; |
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.
Let's add N8N_VERSION_NOTIFICATIONS_ENDPOINT
?
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.
Let's add N8N_LICENSE_SERVER_URL
?
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.
Let's add EXTERNAL_FRONTEND_HOOKS_URLS
?
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.
Let's add N8N_VERSION_NOTIFICATIONS_INFO_URL
?
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.
Let's add N8N_PUBLIC_API_ENDPOINT
?
return this.urls.editor; | ||
} | ||
|
||
/** This is the base url for webhooks */ |
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.
Not sure if the comment is adding much.
That's because the hooks server is acting up again. |
webhookBaseUrl: webhookBaseUrl + config.getEnv('endpoints.webhook'), | ||
webhookWaitingBaseUrl: webhookBaseUrl + config.getEnv('endpoints.webhookWaiting'), | ||
webhookTestBaseUrl: webhookBaseUrl + config.getEnv('endpoints.webhookTest'), |
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.
Maybe expose those 3 URLs as part of the urlService
so it's always centralized. Right now multiple places of the code can generate this URL, possibly leading to inconsistencies.
// TODO: should this use `webhookBaseUrl` ? | ||
const restBaseUrl = this.stripSlash(`${baseUrl}${config.getEnv('endpoints.rest')}`); |
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.
This is correct, the backend
(rest API) always resides with the editor.
The webhooks URL can (if set up like this) point to another pool of servers.
let's say you deploy n8n using https://n8n.omar.cloud
pointing to editor + rest APIs and then another subdomain such as https://webhook.omar.cloud
that points to another pool of servers only running webhook
-type servers for queue mode.
@@ -1,15 +1,15 @@ | |||
export class SamlUrls { | |||
static readonly samlRESTRoot = '/rest/sso/saml'; |
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.
Good catch
webhookBaseUrl: { | ||
format: String, | ||
default: '', | ||
env: 'WEBHOOK_URL', |
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.
Renaming environment variables breaks so many things, I advise against making this change now
baseUrl: { | ||
format: String, | ||
default: '', | ||
env: 'N8N_BASE_URL', |
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.
The problem with this new variable is that users were supposed to set up n8n using N8N_HOST
, N8N_PATH
and N8N_PORT
@@ -138,14 +141,14 @@ export class SamlService { | |||
|
|||
private getRedirectLoginRequestUrl(relayState?: string): BindingContext { | |||
const sp = this.getServiceProviderInstance(); | |||
sp.entitySetting.relayState = relayState ?? getInstanceBaseUrl(); | |||
sp.entitySetting.relayState = relayState ?? this.urlService.editorBaseUrl; |
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.
That's a fair point, maybe in the future we have these services running in separate places (rest API and FE). I'm afraid this would make the PR larger, useless at this time and harder to test. For now I think it's ok to assume that editor and rest api are always on the same host (as they actually are)
I'd love to eventually merge this in - if any of my comments take long, please feel free to disregard! |
rebased. but going to break this out into 2 PRs, one introducing the |
closing this PR since quite a bit of this was already merged, and the remaining bits will need be done from scratch again. |
replaces #6245