mirror of
https://github.com/strapi/strapi.git
synced 2025-09-02 13:23:12 +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 => {
|
||||
if (config[adminOrServer].url.startsWith('http')) {
|
||||
return config[adminOrServer].url;
|
||||
const getAbsoluteUrl = adminOrServer => (config, forAdminBuild = false) => {
|
||||
const { serverUrl, adminUrl } = getConfigUrls(config.server, forAdminBuild);
|
||||
let url = adminOrServer === 'server' ? serverUrl : adminUrl;
|
||||
|
||||
if (url.startsWith('http')) {
|
||||
return url;
|
||||
}
|
||||
|
||||
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'
|
||||
: config.host;
|
||||
: config.server.host;
|
||||
|
||||
return `http://${hostname}:${config.port}${config[adminOrServer].url}`;
|
||||
return `http://${hostname}:${config.server.port}${url}`;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
|
@ -1,6 +1,6 @@
|
||||
// eslint-disable-next-line node/no-extraneous-require
|
||||
const strapiAdmin = require('strapi-admin');
|
||||
const { getConfigUrls } = require('strapi-utils');
|
||||
const { getConfigUrls, getAbsoluteServerUrl } = require('strapi-utils');
|
||||
|
||||
const loadConfiguration = require('../core/app-configuration');
|
||||
const addSlash = require('../utils/addSlash');
|
||||
@ -10,7 +10,7 @@ module.exports = async function() {
|
||||
|
||||
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 adminHost = config.get('server.admin.host', 'localhost');
|
||||
@ -21,7 +21,7 @@ module.exports = async function() {
|
||||
port: adminPort,
|
||||
host: adminHost,
|
||||
options: {
|
||||
backend: serverUrl,
|
||||
backend: getAbsoluteServerUrl(config, true),
|
||||
publicPath: addSlash(adminPath),
|
||||
watchIgnoreFiles: adminWatchIgnoreFiles,
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user