Use root-relative base url for app and extensions (#6923)

* Add Url util class

* Use relative base url for app and extensions

Also use utils/url when working with PUBLIC_URL in other places.
This commit is contained in:
Nicola Krumschmidt
2021-08-26 23:11:21 +02:00
committed by GitHub
parent 5970a7b473
commit 7dfc5dc6af
5 changed files with 102 additions and 20 deletions

View File

@@ -11,6 +11,7 @@ import { Accountability } from '@directus/shared/types';
import getMailer from '../../mailer';
import { Transporter, SendMailOptions } from 'nodemailer';
import prettier from 'prettier';
import { Url } from '../../utils/url';
const liquidEngine = new Liquid({
root: [path.resolve(env.EXTENSIONS_PATH, 'templates'), path.resolve(__dirname, 'templates')],
@@ -100,16 +101,15 @@ export class MailService {
};
function getProjectLogoURL(logoID?: string) {
let projectLogoURL = env.PUBLIC_URL;
if (projectLogoURL.endsWith('/') === false) {
projectLogoURL += '/';
}
const projectLogoUrl = new Url(env.PUBLIC_URL);
if (logoID) {
projectLogoURL += `assets/${logoID}`;
projectLogoUrl.addPath('assets', logoID);
} else {
projectLogoURL += `admin/img/directus-white.png`;
projectLogoUrl.addPath('admin', 'img', 'directus-white.png');
}
return projectLogoURL;
return projectLogoUrl.toString();
}
}
}

View File

@@ -17,6 +17,7 @@ import { AbstractServiceOptions, Item, PrimaryKey, Query, SchemaOverview } from
import { Accountability } from '@directus/shared/types';
import isUrlAllowed from '../utils/is-url-allowed';
import { toArray } from '@directus/shared/utils';
import { Url } from '../utils/url';
import { AuthenticationService } from './authentication';
import { ItemsService, MutationOptions } from './items';
import { MailService } from './mail';
@@ -305,9 +306,9 @@ export class UsersService extends ItemsService {
const payload = { email, scope: 'invite' };
const token = jwt.sign(payload, env.SECRET as string, { expiresIn: '7d' });
const inviteURL = url ?? env.PUBLIC_URL + '/admin/accept-invite';
const acceptURL = inviteURL + '?token=' + token;
const subjectLine = subject ? subject : "You've been invited";
const subjectLine = subject ?? "You've been invited";
const inviteURL = url ? new Url(url) : new Url(env.PUBLIC_URL).addPath('admin', 'accept-invite');
inviteURL.setQuery('token', token);
await mailService.send({
to: email,
@@ -315,7 +316,7 @@ export class UsersService extends ItemsService {
template: {
name: 'user-invitation',
data: {
url: acceptURL,
url: inviteURL.toString(),
email,
},
},