Skip to content
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

Added public url variable for emails #2967

Merged
merged 7 commits into from
Mar 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/cli/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,12 @@ const config = convict({
env: 'N8N_SSL_CERT',
doc: 'SSL Cert for HTTPS Protocol',
},
editorBaseUrl: {
format: String,
default: '',
env: 'N8N_EDITOR_BASE_URL',
doc: 'Public URL where the editor is accessible; path will be concatenated to this base. Also used for emails sent from n8n.',
},

security: {
excludeEndpoints: {
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/Interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ export interface IN8nUISettings {
};
timezone: string;
urlBaseWebhook: string;
urlBaseEditor: string;
versionCli: string;
n8nMetadata?: {
[key: string]: string | number | undefined;
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ import { ExecutionEntity } from './databases/entities/ExecutionEntity';
import { SharedWorkflow } from './databases/entities/SharedWorkflow';
import { AUTH_COOKIE_NAME, RESPONSE_ERROR_MESSAGES } from './constants';
import { credentialsController } from './api/credentials.api';
import { isEmailSetUp } from './UserManagement/UserManagementHelper';
import { getInstanceBaseUrl, isEmailSetUp } from './UserManagement/UserManagementHelper';

require('body-parser-xml')(bodyParser);

Expand Down Expand Up @@ -296,6 +296,7 @@ class App {
maxExecutionTimeout: this.maxExecutionTimeout,
timezone: this.timezone,
urlBaseWebhook,
urlBaseEditor: getInstanceBaseUrl(),
versionCli: '',
oauthCallbackUrls: {
oauth1: `${urlBaseWebhook}${this.restEndpoint}/oauth1-credential/callback`,
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/UserManagement/UserManagementHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ export async function getInstanceOwner(): Promise<User> {
* Return the n8n instance base URL without trailing slash.
*/
export function getInstanceBaseUrl(): string {
const baseUrl = GenericHelpers.getBaseUrl();
const editorBaseUrl = config.get('editorBaseUrl');
const baseUrl = editorBaseUrl ? editorBaseUrl + config.get('path') : GenericHelpers.getBaseUrl();
return baseUrl.endsWith('/') ? baseUrl.slice(0, baseUrl.length - 1) : baseUrl;
}

Expand Down
7 changes: 3 additions & 4 deletions packages/cli/src/UserManagement/routes/passwordReset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import { LoggerProxy as Logger } from 'n8n-workflow';

import { Db, InternalHooksManager, ResponseHelper } from '../..';
import { N8nApp } from '../Interfaces';
import { validatePassword } from '../UserManagementHelper';
import { getInstanceBaseUrl, validatePassword } from '../UserManagementHelper';
import * as UserManagementMailer from '../email';
import type { PasswordResetRequest } from '../../requests';
import { issueCookie } from '../auth/jwt';
import { getBaseUrl } from '../../GenericHelpers';
import config = require('../../../config');

export function passwordResetNamespace(this: N8nApp): void {
Expand Down Expand Up @@ -73,8 +72,8 @@ export function passwordResetNamespace(this: N8nApp): void {

await Db.collections.User!.update(id, { resetPasswordToken, resetPasswordTokenExpiration });

const baseUrl = getBaseUrl();
const url = new URL('/change-password', baseUrl);
const baseUrl = getInstanceBaseUrl();
const url = new URL(`${baseUrl}/change-password`);
url.searchParams.append('userId', id);
url.searchParams.append('token', resetPasswordToken);

Expand Down