mirror of
https://github.com/digitalocean/nginxconfig.io.git
synced 2025-11-06 11:56:15 +08:00
Set the PHP server config per site (#232)
* Set up the php server per site. * Backwards compatibility logic for old config URLs. * Remove php global config tab. * Fix util import in website.conf.js * Fix eslint fails. * Move global php i18n keys to domain * Remove unnecessary domains verification and set fastcgi_pass in unified mode. * Convert return statement to logic operator in php_ustream.js * Move php upstream to outside the server blocks * Remove unnecessary watcher from php domain section * Fix upstream config context and conditional append * Separate backwards compatibility logic. * Remove unused i18n key from php domain and update copyright of these files * Replace all dots for underscore in php_upstream helper * Fix missing space and remove upstream comment from php config. * Fix selects $refs and watch the enable status for phpServer and phpBackupServer. * Change copyright year for all modified files. * Backwards compatibility logic for old config URLs after angularBackwardsCompatibility * Deep merge old php global config from data url, and add safe disable for phpConfigs * Move deep merge function to new helper * Fix missing disable wordpressRules and convert function declaration to arrows in deep merge helper * Fix missing css class in php domain-section
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2020 DigitalOcean
|
||||
Copyright 2021 DigitalOcean
|
||||
|
||||
This code is licensed under the MIT License.
|
||||
You may obtain a copy of the License at
|
||||
38
src/nginxconfig/util/deep_merge.js
Normal file
38
src/nginxconfig/util/deep_merge.js
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
Copyright 2021 DigitalOcean
|
||||
|
||||
This code is licensed under the MIT License.
|
||||
You may obtain a copy of the License at
|
||||
https://github.com/digitalocean/nginxconfig.io/blob/master/LICENSE or https://mit-license.org/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
export default (target, source) => {
|
||||
const merge = (target, source) => {
|
||||
Object.keys(source).forEach((key) => {
|
||||
if (source[key] && typeof source[key] === 'object') {
|
||||
merge(target[key] = target[key] || {}, source[key]);
|
||||
return;
|
||||
}
|
||||
target[key] = source[key];
|
||||
});
|
||||
};
|
||||
merge(target, source);
|
||||
};
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2020 DigitalOcean
|
||||
Copyright 2021 DigitalOcean
|
||||
|
||||
This code is licensed under the MIT License.
|
||||
You may obtain a copy of the License at
|
||||
@@ -28,7 +28,8 @@ import qs from 'qs';
|
||||
import clone from 'clone';
|
||||
import Domain from '../templates/domain';
|
||||
import isObject from './is_object';
|
||||
import backwardsCompatibility from './backwards_compatibility';
|
||||
import angularBackwardsCompatibility from './angular_backwards_compatibility';
|
||||
import vueBackwardsCompatibility from './vue_backwards_compatibility';
|
||||
|
||||
const applyCategories = (categories, target) => {
|
||||
// Work through each potential category
|
||||
@@ -86,7 +87,10 @@ export default (query, domains, global, nextTick) => new Promise(resolve => {
|
||||
});
|
||||
|
||||
// Handle converting nginxconfig.io-angular params to the current version
|
||||
backwardsCompatibility(data);
|
||||
angularBackwardsCompatibility(data);
|
||||
|
||||
// Handle converting vue params to the current version
|
||||
vueBackwardsCompatibility(data);
|
||||
|
||||
// Handle domains
|
||||
if ('domains' in data && isObject(data.domains)) {
|
||||
|
||||
@@ -24,8 +24,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
export default (global, backup = false) => {
|
||||
export default (domain, backup = false) => {
|
||||
const key = `php${backup ? 'Backup' : ''}Server`;
|
||||
if (global.php[key].computed === 'custom') return global.php[`${key}Custom`].computed;
|
||||
return (global.php[key].computed[0] === '/' ? 'unix:' : '') + global.php[key].computed;
|
||||
if (domain.php[key].computed === 'custom') return domain.php[`${key}Custom`].computed;
|
||||
return (domain.php[key].computed[0] === '/' ? 'unix:' : '') + domain.php[key].computed;
|
||||
};
|
||||
|
||||
27
src/nginxconfig/util/php_upstream.js
Normal file
27
src/nginxconfig/util/php_upstream.js
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
Copyright 2021 DigitalOcean
|
||||
|
||||
This code is licensed under the MIT License.
|
||||
You may obtain a copy of the License at
|
||||
https://github.com/digitalocean/nginxconfig.io/blob/master/LICENSE or https://mit-license.org/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
export default (domain) => `php_${domain.server.domain.computed.replace(/\./g, '_')}`;
|
||||
71
src/nginxconfig/util/vue_backwards_compatibility.js
Normal file
71
src/nginxconfig/util/vue_backwards_compatibility.js
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
Copyright 2021 DigitalOcean
|
||||
|
||||
This code is licensed under the MIT License.
|
||||
You may obtain a copy of the License at
|
||||
https://github.com/digitalocean/nginxconfig.io/blob/master/LICENSE or https://mit-license.org/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import isObject from './is_object';
|
||||
import deepMerge from './deep_merge';
|
||||
|
||||
// Handle converting the old query format to our new query params
|
||||
export default data => {
|
||||
// Handle converting old domain settings to new ones
|
||||
if ('global' in data && isObject(data.global)) {
|
||||
// Handle specifics global data
|
||||
const mappedData = {
|
||||
php: {},
|
||||
};
|
||||
|
||||
// Keys to map
|
||||
const keysToMap = {
|
||||
php: [
|
||||
'phpServer',
|
||||
'phpServerCustom',
|
||||
'phpBackupServer',
|
||||
'phpBackupServerCustom',
|
||||
],
|
||||
};
|
||||
|
||||
for (const key in data.global) {
|
||||
if (!Object.prototype.hasOwnProperty.call(data.global, key)) continue;
|
||||
|
||||
// Skip if key doesn't need to be mapped
|
||||
if (!Object.prototype.hasOwnProperty.call(keysToMap, key)) continue;
|
||||
|
||||
for (const key2 in data.global[key]) {
|
||||
if (!Object.prototype.hasOwnProperty.call(data.global[key], key2)) continue;
|
||||
|
||||
if (keysToMap[key].includes(key2)) {
|
||||
mappedData[key][key2] = data.global[key][key2];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const key in data.domains) {
|
||||
if (!Object.prototype.hasOwnProperty.call(data.domains, key)) continue;
|
||||
|
||||
// Deep merge the mapped data
|
||||
deepMerge(data.domains[key], mappedData);
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user