diff options
Diffstat (limited to '')
-rw-r--r-- | lib/config/default.js | 68 | ||||
-rw-r--r-- | lib/config/environment.js | 28 | ||||
-rw-r--r-- | lib/config/index.js | 71 | ||||
-rw-r--r-- | lib/config/oldDefault.js | 42 |
4 files changed, 131 insertions, 78 deletions
diff --git a/lib/config/default.js b/lib/config/default.js index 7407ec60..19ddccf6 100644 --- a/lib/config/default.js +++ b/lib/config/default.js @@ -2,11 +2,11 @@ module.exports = { domain: '', - urlpath: '', + urlPath: '', port: 3000, - urladdport: false, - alloworigin: ['localhost'], - usessl: false, + urlAddPort: false, + allowOrigin: ['localhost'], + useSSL: false, hsts: { enable: true, maxAgeSeconds: 31536000, @@ -21,42 +21,40 @@ module.exports = { upgradeInsecureRequests: 'auto', reportURI: undefined }, - protocolusessl: false, - usecdn: true, - allowanonymous: true, - allowanonymousedits: false, - allowfreeurl: false, - defaultpermission: 'editable', - dburl: '', + protocolUseSSL: false, + useCDN: true, + allowAnonymous: true, + allowAnonymousEdits: false, + allowFreeURL: false, + defaultPermission: 'editable', + dbURL: '', db: {}, // ssl path - sslkeypath: '', - sslcertpath: '', - sslcapath: '', - dhparampath: '', + sslKeyPath: '', + sslCertPath: '', + sslCAPath: '', + dhParamPath: '', // other path - tmppath: './tmp', - defaultnotepath: './public/default.md', - docspath: './public/docs', - indexpath: './public/views/index.ejs', - hackmdpath: './public/views/hackmd.ejs', - errorpath: './public/views/error.ejs', - prettypath: './public/views/pretty.ejs', - slidepath: './public/views/slide.ejs', + tmpPath: './tmp', + defaultNotePath: './public/default.md', + docsPath: './public/docs', + indexPath: './public/views/index.ejs', + hackmdPath: './public/views/hackmd.ejs', + errorPath: './public/views/error.ejs', + prettyPath: './public/views/pretty.ejs', + slidePath: './public/views/slide.ejs', // session - sessionname: 'connect.sid', - sessionsecret: 'secret', - sessionlife: 14 * 24 * 60 * 60 * 1000, // 14 days - staticcachetime: 1 * 24 * 60 * 60 * 1000, // 1 day + sessionName: 'connect.sid', + sessionSecret: 'secret', + sessionLife: 14 * 24 * 60 * 60 * 1000, // 14 days + staticCacheTime: 1 * 24 * 60 * 60 * 1000, // 1 day // socket.io - heartbeatinterval: 5000, - heartbeattimeout: 10000, + heartbeatInterval: 5000, + heartbeatTimeout: 10000, // document - documentmaxlength: 100000, + documentMaxLength: 100000, // image upload setting, available options are imgur/s3/filesystem - imageuploadtype: 'filesystem', - // legacy variable name for imageuploadtype - imageUploadType: undefined, + imageUploadType: 'filesystem', imgur: { clientID: undefined }, @@ -133,6 +131,6 @@ module.exports = { } }, email: true, - allowemailregister: true, - allowpdfexport: true + allowEmailRegister: true, + allowPDFExport: true } diff --git a/lib/config/environment.js b/lib/config/environment.js index ddc09e10..cab3bc3e 100644 --- a/lib/config/environment.js +++ b/lib/config/environment.js @@ -4,10 +4,10 @@ const {toBooleanConfig, toArrayConfig, toIntegerConfig} = require('./utils') module.exports = { domain: process.env.HMD_DOMAIN, - urlpath: process.env.HMD_URL_PATH, + urlPath: process.env.HMD_URL_PATH, port: toIntegerConfig(process.env.HMD_PORT), - urladdport: toBooleanConfig(process.env.HMD_URL_ADDPORT), - usessl: toBooleanConfig(process.env.HMD_USESSL), + urlAddPort: toBooleanConfig(process.env.HMD_URL_ADDPORT), + useSSL: toBooleanConfig(process.env.HMD_USESSL), hsts: { enable: toBooleanConfig(process.env.HMD_HSTS_ENABLE), maxAgeSeconds: process.env.HMD_HSTS_MAX_AGE, @@ -18,15 +18,15 @@ module.exports = { enable: toBooleanConfig(process.env.HMD_CSP_ENABLE), reportURI: process.env.HMD_CSP_REPORTURI }, - protocolusessl: toBooleanConfig(process.env.HMD_PROTOCOL_USESSL), - alloworigin: toArrayConfig(process.env.HMD_ALLOW_ORIGIN), - usecdn: toBooleanConfig(process.env.HMD_USECDN), - allowanonymous: toBooleanConfig(process.env.HMD_ALLOW_ANONYMOUS), - allowanonymousedits: toBooleanConfig(process.env.HMD_ALLOW_ANONYMOUS_EDITS), - allowfreeurl: toBooleanConfig(process.env.HMD_ALLOW_FREEURL), - defaultpermission: process.env.HMD_DEFAULT_PERMISSION, - dburl: process.env.HMD_DB_URL, - imageuploadtype: process.env.HMD_IMAGE_UPLOAD_TYPE, + protocolUseSSL: toBooleanConfig(process.env.HMD_PROTOCOL_USESSL), + allowOrigin: toArrayConfig(process.env.HMD_ALLOW_ORIGIN), + useCDN: toBooleanConfig(process.env.HMD_USECDN), + allowAnonymous: toBooleanConfig(process.env.HMD_ALLOW_ANONYMOUS), + allowAnonymousEdits: toBooleanConfig(process.env.HMD_ALLOW_ANONYMOUS_EDITS), + allowFreeURL: toBooleanConfig(process.env.HMD_ALLOW_FREEURL), + defaultPermission: process.env.HMD_DEFAULT_PERMISSION, + dbURL: process.env.HMD_DB_URL, + imageUploadType: process.env.HMD_IMAGE_UPLOAD_TYPE, imgur: { clientID: process.env.HMD_IMGUR_CLIENTID }, @@ -102,6 +102,6 @@ module.exports = { } }, email: toBooleanConfig(process.env.HMD_EMAIL), - allowemailregister: toBooleanConfig(process.env.HMD_ALLOW_EMAIL_REGISTER), - allowpdfexport: toBooleanConfig(process.env.HMD_ALLOW_PDF_EXPORT) + allowEmailRegister: toBooleanConfig(process.env.HMD_ALLOW_EMAIL_REGISTER), + allowPDFExport: toBooleanConfig(process.env.HMD_ALLOW_PDF_EXPORT) } diff --git a/lib/config/index.js b/lib/config/index.js index abcd2b3e..fae51e52 100644 --- a/lib/config/index.js +++ b/lib/config/index.js @@ -27,6 +27,7 @@ const fileConfig = fs.existsSync(configFilePath) ? require(configFilePath)[env] let config = require('./default') merge(config, require('./defaultSSL')) +merge(config, require('./oldDefault')) merge(config, debugConfig) merge(config, packageConfig) merge(config, fileConfig) @@ -51,35 +52,35 @@ if (config.ldap.tlsca) { // Permission config.permission = Permission -if (!config.allowanonymous && !config.allowanonymousedits) { +if (!config.allowAnonymous && !config.allowAnonymousedits) { delete config.permission.freely } -if (!(config.defaultpermission in config.permission)) { - config.defaultpermission = config.permission.editable +if (!(config.defaultPermission in config.permission)) { + config.defaultPermission = config.permission.editable } // cache result, cannot change config in runtime!!! config.isStandardHTTPsPort = (function isStandardHTTPsPort () { - return config.usessl && config.port === 443 + return config.useSSL && config.port === 443 })() config.isStandardHTTPPort = (function isStandardHTTPPort () { - return !config.usessl && config.port === 80 + return !config.useSSL && config.port === 80 })() // cache serverURL -config.serverurl = (function getserverurl () { +config.serverURL = (function getserverurl () { var url = '' if (config.domain) { - var protocol = config.protocolusessl ? 'https://' : 'http://' + var protocol = config.protocolUseSSL ? 'https://' : 'http://' url = protocol + config.domain - if (config.urladdport) { + if (config.urlAddPort) { if (!config.isStandardHTTPPort || !config.isStandardHTTPsPort) { url += ':' + config.port } } } - if (config.urlpath) { - url += '/' + config.urlpath + if (config.urlPath) { + url += '/' + config.urlPath } return url })() @@ -97,21 +98,33 @@ config.isGitLabEnable = config.gitlab.clientID && config.gitlab.clientSecret config.isMattermostEnable = config.mattermost.clientID && config.mattermost.clientSecret config.isLDAPEnable = config.ldap.url config.isSAMLEnable = config.saml.idpSsoUrl -config.isPDFExportEnable = config.allowpdfexport +config.isPDFExportEnable = config.allowPDFExport // merge legacy values -if (config.imageUploadType && !config.imageuploadtype) { - config.imageuploadtype = config.imageUploadType +let keys = Object.keys(config) +const uppercase = /[A-Z]/ +for (let i = keys.length; i--;) { + let lowercaseKey = keys[i].toLowerCase() + // if the config contains uppercase letters + // and a lowercase version of this setting exists + // and the config with uppercase is not set + // we set the new config using the old key. + if (uppercase.test(keys[i]) && + config[lowercaseKey] && + !config[keys[1]]) { + logger.warn('config.js contains deprecated lowercase setting for ' + keys[i] + '. Please change your config.js file to replace ' + lowercaseKey + ' with ' + keys[i]) + config[keys[i]] = config[lowercaseKey] + } } // Validate upload upload providers -if (['filesystem', 's3', 'minio', 'imgur'].indexOf(config.imageuploadtype) === -1) { +if (['filesystem', 's3', 'minio', 'imgur'].indexOf(config.imageUploadType) === -1) { logger.error('"imageuploadtype" is not correctly set. Please use "filesystem", "s3", "minio" or "imgur". Defaulting to "imgur"') - config.imageuploadtype = 'imgur' + config.imageUploadType = 'imgur' } // figure out mime types for image uploads -switch (config.imageuploadtype) { +switch (config.imageUploadType) { case 'imgur': config.allowedUploadMimeTypes = [ 'image/jpeg', @@ -131,22 +144,22 @@ switch (config.imageuploadtype) { } // generate correct path -config.sslcapath.forEach(function (capath, i, array) { +config.sslCAPath.forEach(function (capath, i, array) { array[i] = path.resolve(appRootPath, capath) }) -config.sslcertpath = path.join(appRootPath, config.sslcertpath) -config.sslkeypath = path.join(appRootPath, config.sslkeypath) -config.dhparampath = path.join(appRootPath, config.dhparampath) - -config.tmppath = path.join(appRootPath, config.tmppath) -config.defaultnotepath = path.join(appRootPath, config.defaultnotepath) -config.docspath = path.join(appRootPath, config.docspath) -config.indexpath = path.join(appRootPath, config.indexpath) -config.hackmdpath = path.join(appRootPath, config.hackmdpath) -config.errorpath = path.join(appRootPath, config.errorpath) -config.prettypath = path.join(appRootPath, config.prettypath) -config.slidepath = path.join(appRootPath, config.slidepath) +config.sslCertPath = path.join(appRootPath, config.sslCertPath) +config.sslKeyPath = path.join(appRootPath, config.sslKeyPath) +config.dhParamPath = path.join(appRootPath, config.dhParamPath) + +config.tmpPath = path.join(appRootPath, config.tmpPath) +config.defaultNotePath = path.join(appRootPath, config.defaultNotePath) +config.docsPath = path.join(appRootPath, config.docsPath) +config.indexPath = path.join(appRootPath, config.indexPath) +config.hackmdPath = path.join(appRootPath, config.hackmdPath) +config.errorPath = path.join(appRootPath, config.errorPath) +config.prettyPath = path.join(appRootPath, config.prettyPath) +config.slidePath = path.join(appRootPath, config.slidePath) // make config readonly config = deepFreeze(config) diff --git a/lib/config/oldDefault.js b/lib/config/oldDefault.js new file mode 100644 index 00000000..90942951 --- /dev/null +++ b/lib/config/oldDefault.js @@ -0,0 +1,42 @@ +'use strict' + +module.exports = { + urlpath: undefined, + urladdport: undefined, + alloworigin: undefined, + usessl: undefined, + protocolusessl: undefined, + usecdn: undefined, + allowanonymous: undefined, + allowanonymousedits: undefined, + allowfreeurl: undefined, + defaultpermission: undefined, + dburl: undefined, + // ssl path + sslkeypath: undefined, + sslcertpath: undefined, + sslcapath: undefined, + dhparampath: undefined, + // other path + tmppath: undefined, + defaultnotepath: undefined, + docspath: undefined, + indexpath: undefined, + hackmdpath: undefined, + errorpath: undefined, + prettypath: undefined, + slidepath: undefined, + // session + sessionname: undefined, + sessionsecret: undefined, + sessionlife: undefined, + staticcachetime: undefined, + // socket.io + heartbeatinterval: undefined, + heartbeattimeout: undefined, + // document + documentmaxlength: undefined, + imageuploadtype: undefined, + allowemailregister: undefined, + allowpdfexport: undefined +} |