mirror of
https://github.com/strapi/strapi.git
synced 2025-07-18 22:45:47 +00:00

* add possibility to use strapi on a non-root base url path * fix documentation password form * use server.url and admin.url in config Signed-off-by: Pierre Noël <pierre.noel@strapi.io> * update doc proxy Signed-off-by: Pierre Noël <pierre.noel@strapi.io> * move server.url location in config Signed-off-by: Pierre Noël <pierre.noel@strapi.io> * refacto Signed-off-by: Pierre Noël <pierre.noel@strapi.io> * add possibility to put relative urls Signed-off-by: Pierre Noël <pierre.noel@strapi.io> * allow '/' as an admin url + refacto Signed-off-by: Pierre Noël <pierre.noel@strapi.io> * update yarn.lock Signed-off-by: Pierre Noël <petersg83@gmail.com> * refacto Signed-off-by: Pierre Noël <petersg83@gmail.com> * Remove default proxy option Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com> * fix github provider Signed-off-by: Pierre Noël <petersg83@gmail.com> * fix github login Signed-off-by: Pierre Noël <petersg83@gmail.com> * Remove files that should be here Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com> Co-authored-by: Pierre Noël <pierre.noel@strapi.io> Co-authored-by: Alexandre Bodin <bodin.alex@gmail.com>
63 lines
1.8 KiB
JavaScript
63 lines
1.8 KiB
JavaScript
const _ = require('lodash');
|
|
const { getCommonBeginning } = require('./stringFormatting');
|
|
|
|
const getConfigUrls = (serverConfig, forAdminBuild = false) => {
|
|
// Defines serverUrl value
|
|
let serverUrl = _.get(serverConfig, 'url', '');
|
|
serverUrl = _.trim(serverUrl, '/ ');
|
|
if (typeof serverUrl !== 'string') {
|
|
throw new Error('Invalid server url config. Make sure the url is a string.');
|
|
}
|
|
if (serverUrl.startsWith('http')) {
|
|
try {
|
|
serverUrl = _.trim(new URL(serverConfig.url).toString(), '/');
|
|
} catch (e) {
|
|
throw new Error(
|
|
'Invalid server url config. Make sure the url defined in server.js is valid.'
|
|
);
|
|
}
|
|
} else if (serverUrl !== '') {
|
|
serverUrl = `/${serverUrl}`;
|
|
}
|
|
|
|
// Defines adminUrl value
|
|
let adminUrl = _.get(serverConfig, 'admin.url', '/admin');
|
|
adminUrl = _.trim(adminUrl, '/ ');
|
|
if (typeof adminUrl !== 'string') {
|
|
throw new Error('Invalid admin url config. Make sure the url is a non-empty string.');
|
|
}
|
|
if (adminUrl.startsWith('http')) {
|
|
try {
|
|
adminUrl = _.trim(new URL(adminUrl).toString(), '/');
|
|
} catch (e) {
|
|
throw new Error('Invalid admin url config. Make sure the url defined in server.js is valid.');
|
|
}
|
|
} else {
|
|
adminUrl = `${serverUrl}/${adminUrl}`;
|
|
}
|
|
|
|
// Defines adminPath value
|
|
let adminPath = adminUrl;
|
|
if (
|
|
serverUrl.startsWith('http') &&
|
|
adminUrl.startsWith('http') &&
|
|
new URL(adminUrl).origin === new URL(serverUrl).origin &&
|
|
!forAdminBuild
|
|
) {
|
|
adminPath = adminUrl.replace(getCommonBeginning(serverUrl, adminUrl), '');
|
|
adminPath = `/${_.trim(adminPath, '/')}`;
|
|
} else if (adminUrl.startsWith('http')) {
|
|
adminPath = new URL(adminUrl).pathname;
|
|
}
|
|
|
|
return {
|
|
serverUrl,
|
|
adminUrl,
|
|
adminPath,
|
|
};
|
|
};
|
|
|
|
module.exports = {
|
|
getConfigUrls,
|
|
};
|