Single file config + formatting fixes!
parent
6a70c53107
commit
7fa39d4bcc
|
@ -1,4 +1,5 @@
|
||||||
import sslProfiles from '../../util/ssl_profiles';
|
import sslProfiles from '../../util/ssl_profiles';
|
||||||
|
import websiteConf from './website.conf';
|
||||||
|
|
||||||
export default (domains, global) => {
|
export default (domains, global) => {
|
||||||
const config = {};
|
const config = {};
|
||||||
|
@ -105,7 +106,10 @@ export default (domains, global) => {
|
||||||
|
|
||||||
// Single file configs
|
// Single file configs
|
||||||
if (!global.tools.modularizedStructure.computed) {
|
if (!global.tools.modularizedStructure.computed) {
|
||||||
// TODO: figure out merging in all the other configs
|
for (const domain of domains) {
|
||||||
|
config.http.push([`# ${domain.server.domain.computed}`, '']);
|
||||||
|
config.http.push(...websiteConf(domain, domains, global));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Done!
|
// Done!
|
||||||
|
|
|
@ -132,7 +132,7 @@ export default (domain, domains, global) => {
|
||||||
&& (!domain.reverseProxy.reverseProxy.computed || domain.reverseProxy.path.computed !== '/')) {
|
&& (!domain.reverseProxy.reverseProxy.computed || domain.reverseProxy.path.computed !== '/')) {
|
||||||
serverConfig.push([`# index.${domain.routing.fallbackHtml.computed ? 'html' : (domain.routing.fallbackPhp.computed ? 'php' : '')} fallback`, '']);
|
serverConfig.push([`# index.${domain.routing.fallbackHtml.computed ? 'html' : (domain.routing.fallbackPhp.computed ? 'php' : '')} fallback`, '']);
|
||||||
serverConfig.push(['location /', {
|
serverConfig.push(['location /', {
|
||||||
try_files: `$uri $uri/ /index.${domain.routing.fallbackHtml.computed ? '.html' : (domain.routing.fallbackPhp.computed ? '.php?$query_string' : '')}`,
|
try_files: `$uri $uri/ /index.${domain.routing.fallbackHtml.computed ? 'html' : (domain.routing.fallbackPhp.computed ? 'php?$query_string' : '')}`,
|
||||||
}]);
|
}]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,27 @@
|
||||||
import isObject from '../util/is_object';
|
import isObject from '../util/is_object';
|
||||||
|
|
||||||
|
const isBlock = item => {
|
||||||
|
// If an object, or kv entries, this is considered a block
|
||||||
|
return isObject(item) || (Array.isArray(item) && item.every(i => Array.isArray(i) && i.length === 2));
|
||||||
|
};
|
||||||
|
|
||||||
|
const longestKey = items => {
|
||||||
|
let longest = 0;
|
||||||
|
|
||||||
|
for (const item of items) {
|
||||||
|
// Only consider up to the first block
|
||||||
|
if (isBlock(item[1]))
|
||||||
|
return longest;
|
||||||
|
|
||||||
|
// If this is the new longest, and not a comment, use this
|
||||||
|
if (item[0].length > longest && !item[0].startsWith('#'))
|
||||||
|
longest = item[0].length;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Done!
|
||||||
|
return longest;
|
||||||
|
};
|
||||||
|
|
||||||
const recurse = (entriesOrObject, depth) => {
|
const recurse = (entriesOrObject, depth) => {
|
||||||
// Support an object or kv array entries
|
// Support an object or kv array entries
|
||||||
// Convert to entries if given an object
|
// Convert to entries if given an object
|
||||||
|
@ -10,32 +32,40 @@ const recurse = (entriesOrObject, depth) => {
|
||||||
|
|
||||||
// Initial values
|
// Initial values
|
||||||
let retVal = '';
|
let retVal = '';
|
||||||
const longestKeyLen = entries.reduce((prev, current) => {
|
let longestKeyLen = longestKey(entries);
|
||||||
if (!current[0].startsWith('#') && current[0].length > prev)
|
|
||||||
return current[0].length;
|
|
||||||
return prev;
|
|
||||||
}, 0);
|
|
||||||
const indent = (' ').repeat(depth);
|
const indent = (' ').repeat(depth);
|
||||||
|
|
||||||
|
// Track whether the previous was a block, for indentation
|
||||||
|
let previousBlock = false;
|
||||||
|
|
||||||
// Loop over every kv pair
|
// Loop over every kv pair
|
||||||
for (const item of entries) {
|
for (let i = 0; i < entries.length; i++) {
|
||||||
// If an object, or kv entries, recurse
|
const item = entries[i];
|
||||||
if (isObject(item[1]) || (Array.isArray(item[1]) && item[1].every(i => Array.isArray(i) && i.length === 2))) {
|
|
||||||
|
// If a block (object or kv entries), recurse
|
||||||
|
if (isBlock(item[1])) {
|
||||||
// Recurse
|
// Recurse
|
||||||
retVal += '\n' + indent + item[0] + ' {\n';
|
retVal += '\n' + indent + item[0] + ' {\n';
|
||||||
retVal += recurse(item[1], depth + 1);
|
retVal += recurse(item[1], depth + 1);
|
||||||
retVal += indent + '}\n\n';
|
retVal += indent + '}\n\n';
|
||||||
|
|
||||||
// Done
|
// Done
|
||||||
|
previousBlock = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update key length if we've just left a block
|
||||||
|
if (previousBlock) {
|
||||||
|
longestKeyLen = longestKey(entries.slice(i));
|
||||||
|
previousBlock = false;
|
||||||
|
}
|
||||||
|
|
||||||
// Otherwise, assume it can be made a string
|
// Otherwise, assume it can be made a string
|
||||||
// Ensure we're working with an array
|
// Ensure we're working with an array
|
||||||
const val = Array.isArray(item[1]) ? item[1] : [item[1]];
|
const val = Array.isArray(item[1]) ? item[1] : [item[1]];
|
||||||
|
|
||||||
// Calculate spacing
|
// Calculate spacing
|
||||||
const keyValSpacing = (longestKeyLen - item[0].length) + 4;
|
const keyValSpacing = (longestKeyLen - item[0].length) + 1;
|
||||||
const keyValIndent = (' ').repeat(Math.max(keyValSpacing, 0));
|
const keyValIndent = (' ').repeat(Math.max(keyValSpacing, 0));
|
||||||
|
|
||||||
// Work through each item in the array
|
// Work through each item in the array
|
||||||
|
|
Loading…
Reference in New Issue