mirror of
https://github.com/strapi/strapi.git
synced 2025-09-03 05:39:36 +00:00
make serverUrl absolute for watch-admin (#6405)
Signed-off-by: Pierre Noël <petersg83@gmail.com>
This commit is contained in:
parent
4a6ef41201
commit
c12c6e95b4
@ -57,17 +57,20 @@ const getConfigUrls = (serverConfig, forAdminBuild = false) => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const getAbsoluteUrl = adminOrServer => config => {
|
const getAbsoluteUrl = adminOrServer => (config, forAdminBuild = false) => {
|
||||||
if (config[adminOrServer].url.startsWith('http')) {
|
const { serverUrl, adminUrl } = getConfigUrls(config.server, forAdminBuild);
|
||||||
return config[adminOrServer].url;
|
let url = adminOrServer === 'server' ? serverUrl : adminUrl;
|
||||||
|
|
||||||
|
if (url.startsWith('http')) {
|
||||||
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
let hostname =
|
let hostname =
|
||||||
config.environment === 'development' && ['127.0.0.1', '0.0.0.0'].includes(config.host)
|
config.environment === 'development' && ['127.0.0.1', '0.0.0.0'].includes(config.server.host)
|
||||||
? 'localhost'
|
? 'localhost'
|
||||||
: config.host;
|
: config.server.host;
|
||||||
|
|
||||||
return `http://${hostname}:${config.port}${config[adminOrServer].url}`;
|
return `http://${hostname}:${config.server.port}${url}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// eslint-disable-next-line node/no-extraneous-require
|
// eslint-disable-next-line node/no-extraneous-require
|
||||||
const strapiAdmin = require('strapi-admin');
|
const strapiAdmin = require('strapi-admin');
|
||||||
const { getConfigUrls } = require('strapi-utils');
|
const { getConfigUrls, getAbsoluteServerUrl } = require('strapi-utils');
|
||||||
|
|
||||||
const loadConfiguration = require('../core/app-configuration');
|
const loadConfiguration = require('../core/app-configuration');
|
||||||
const addSlash = require('../utils/addSlash');
|
const addSlash = require('../utils/addSlash');
|
||||||
@ -10,7 +10,7 @@ module.exports = async function() {
|
|||||||
|
|
||||||
const config = loadConfiguration(dir);
|
const config = loadConfiguration(dir);
|
||||||
|
|
||||||
const { serverUrl, adminPath } = getConfigUrls(config.get('server'), true);
|
const { adminPath } = getConfigUrls(config.get('server'), true);
|
||||||
|
|
||||||
const adminPort = config.get('server.admin.port', 8000);
|
const adminPort = config.get('server.admin.port', 8000);
|
||||||
const adminHost = config.get('server.admin.host', 'localhost');
|
const adminHost = config.get('server.admin.host', 'localhost');
|
||||||
@ -21,7 +21,7 @@ module.exports = async function() {
|
|||||||
port: adminPort,
|
port: adminPort,
|
||||||
host: adminHost,
|
host: adminHost,
|
||||||
options: {
|
options: {
|
||||||
backend: serverUrl,
|
backend: getAbsoluteServerUrl(config, true),
|
||||||
publicPath: addSlash(adminPath),
|
publicPath: addSlash(adminPath),
|
||||||
watchIgnoreFiles: adminWatchIgnoreFiles,
|
watchIgnoreFiles: adminWatchIgnoreFiles,
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user