-
Notifications
You must be signed in to change notification settings - Fork 9.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Move getInstaceBaseUrl to the InstanceService (no-changelog)
- Loading branch information
1 parent
b7c5c74
commit 0a14156
Showing
11 changed files
with
104 additions
and
56 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Service } from 'typedi'; | ||
import config from '@/config'; | ||
|
||
@Service() | ||
export class InstanceService { | ||
/** | ||
* Return the n8n instance base URL without trailing slash. | ||
*/ | ||
getInstanceBaseUrl(): string { | ||
const n8nBaseUrl = config.getEnv('editorBaseUrl') || this.getWebhookBaseUrl(); | ||
return n8nBaseUrl.endsWith('/') ? n8nBaseUrl.slice(0, n8nBaseUrl.length - 1) : n8nBaseUrl; | ||
} | ||
|
||
getWebhookBaseUrl() { | ||
let urlBaseWebhook = process.env.WEBHOOK_URL ?? this.getBaseUrl(); | ||
if (!urlBaseWebhook.endsWith('/')) { | ||
urlBaseWebhook += '/'; | ||
} | ||
return urlBaseWebhook; | ||
} | ||
|
||
/** | ||
* Returns the base URL n8n is reachable from | ||
*/ | ||
private getBaseUrl() { | ||
const protocol = config.getEnv('protocol'); | ||
const host = config.getEnv('host'); | ||
const port = config.getEnv('port'); | ||
const path = config.getEnv('path'); | ||
|
||
if ((protocol === 'http' && port === 80) || (protocol === 'https' && port === 443)) { | ||
return `${protocol}://${host}${path}`; | ||
} | ||
return `${protocol}://${host}:${port}${path}`; | ||
} | ||
} |
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
Oops, something went wrong.