mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 10:21:36 +03:00
77996d1ee4
- Makes the logic for determining the admin and frontend vhost args independent and easier to test - Moved the tests to specifically test the vhost utils & removed proxyquire as a dependency - We want to breakdown the current parent app into the existing core/app.js and boot code, allowing us to decouple the backend and frontend further - This is all part of the refactoring to separate server and frontend completely
40 lines
1.2 KiB
JavaScript
40 lines
1.2 KiB
JavaScript
const config = require('../../../shared/config');
|
|
const escapeRegExp = require('lodash/escapeRegExp');
|
|
const {URL} = require('url');
|
|
|
|
const DEFAULT_HOST_ARG = /.*/;
|
|
|
|
const getHostsFromConfig = () => {
|
|
const frontendHost = new URL(config.getSiteUrl()).hostname;
|
|
|
|
const backendHost = config.getAdminUrl() ? (new URL(config.getAdminUrl()).hostname) : '';
|
|
const hasSeparateBackendHost = backendHost && backendHost !== frontendHost;
|
|
|
|
return {
|
|
backendHost,
|
|
hasSeparateBackendHost
|
|
};
|
|
};
|
|
|
|
/**
|
|
*
|
|
* @returns {string|RegExp}
|
|
*/
|
|
module.exports.getBackendHostArg = () => {
|
|
const {backendHost, hasSeparateBackendHost} = getHostsFromConfig();
|
|
|
|
// with a separate admin url only serve on that host, otherwise serve on all hosts
|
|
return (hasSeparateBackendHost) && backendHost ? backendHost : DEFAULT_HOST_ARG;
|
|
};
|
|
|
|
/**
|
|
*
|
|
* @returns {string|RegExp}
|
|
*/
|
|
module.exports.getFrontendHostArg = () => {
|
|
const {backendHost, hasSeparateBackendHost} = getHostsFromConfig();
|
|
|
|
// with a separate admin url we adjust the frontend vhost to exclude requests to that host, otherwise serve on all hosts
|
|
return (hasSeparateBackendHost && backendHost) ? new RegExp(`^(?!${escapeRegExp(backendHost)}).*`) : DEFAULT_HOST_ARG;
|
|
};
|