Skip to content

Commit 57c47a6

Browse files
authored
Merge pull request #758 from SISheogorath/cleanup/config
Change config to camel case with backwards compatibility
2 parents ea1d35e + 2411dff commit 57c47a6

File tree

29 files changed

+291
-238
lines changed

29 files changed

+291
-238
lines changed

README.md

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ There are some config settings you need to change in the files below.
147147
| `HMD_URL_ADDPORT` | `true` or `false` | set to add port on callback URL (ports `80` or `443` won't be applied) (only applied when domain is set) |
148148
| `HMD_USECDN` | `true` or `false` | set to use CDN resources or not (default is `true`) |
149149
| `HMD_ALLOW_ANONYMOUS` | `true` or `false` | set to allow anonymous usage (default is `true`) |
150-
| `HMD_ALLOW_ANONYMOUS_EDITS` | `true` or `false` | if `allowanonymous` is `true`, allow users to select `freely` permission, allowing guests to edit existing notes (default is `false`) |
150+
| `HMD_ALLOW_ANONYMOUS_EDITS` | `true` or `false` | if `allowAnonymous` is `true`, allow users to select `freely` permission, allowing guests to edit existing notes (default is `false`) |
151151
| `HMD_ALLOW_FREEURL` | `true` or `false` | set to allow new note creation by accessing a nonexistent note URL |
152152
| `HMD_DEFAULT_PERMISSION` | `freely`, `editable`, `limited`, `locked` or `private` | set notes default permission (only applied on signed users) |
153153
| `HMD_DB_URL` | `mysql://localhost:3306/database` | set the database URL |
@@ -215,46 +215,46 @@ There are some config settings you need to change in the files below.
215215
| --------- | ------ | ----------- |
216216
| `debug` | `true` or `false` | set debug mode, show more logs |
217217
| `domain` | `localhost` | domain name |
218-
| `urlpath` | `hackmd` | sub URL path, like `www.example.com/<urlpath>` |
218+
| `urlPath` | `hackmd` | sub URL path, like `www.example.com/<urlpath>` |
219219
| `port` | `80` | web app port |
220-
| `alloworigin` | `['localhost']` | domain name whitelist |
221-
| `usessl` | `true` or `false` | set to use SSL server (if `true`, will auto turn on `protocolusessl`) |
220+
| `allowOrigin` | `['localhost']` | domain name whitelist |
221+
| `useSSL` | `true` or `false` | set to use SSL server (if `true`, will auto turn on `protocolUseSSL`) |
222222
| `hsts` | `{"enable": true, "maxAgeSeconds": 31536000, "includeSubdomains": true, "preload": true}` | [HSTS](https://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security) options to use with HTTPS (default is the example value, max age is a year) |
223-
| `csp` | `{"enable": true, "directives": {"scriptSrc": "trustworthy-scripts.example.com"}, "upgradeInsecureRequests": "auto", "addDefaults": true}` | Configures [Content Security Policy](https://helmetjs.github.io/docs/csp/). Directives are passed to Helmet - see [their documentation](https://helmetjs.github.io/docs/csp/) for more information on the format. Some defaults are added to the configured values so that the application doesn't break. To disable this behaviour, set `addDefaults` to `false`. Further, if `usecdn` is on, some CDN locations are allowed too. By default (`auto`), insecure (HTTP) requests are upgraded to HTTPS via CSP if `usessl` is on. To change this behaviour, set `upgradeInsecureRequests` to either `true` or `false`. |
224-
| `protocolusessl` | `true` or `false` | set to use SSL protocol for resources path (only applied when domain is set) |
225-
| `urladdport` | `true` or `false` | set to add port on callback URL (ports `80` or `443` won't be applied) (only applied when domain is set) |
226-
| `usecdn` | `true` or `false` | set to use CDN resources or not (default is `true`) |
227-
| `allowanonymous` | `true` or `false` | set to allow anonymous usage (default is `true`) |
228-
| `allowanonymousedits` | `true` or `false` | if `allowanonymous` is `true`: allow users to select `freely` permission, allowing guests to edit existing notes (default is `false`) |
229-
| `allowfreeurl` | `true` or `false` | set to allow new note creation by accessing a nonexistent note URL |
230-
| `defaultpermission` | `freely`, `editable`, `limited`, `locked`, `protected` or `private` | set notes default permission (only applied on signed users) |
231-
| `dburl` | `mysql://localhost:3306/database` | set the db URL; if set, then db config (below) won't be applied |
223+
| `csp` | `{"enable": true, "directives": {"scriptSrc": "trustworthy-scripts.example.com"}, "upgradeInsecureRequests": "auto", "addDefaults": true}` | Configures [Content Security Policy](https://helmetjs.github.io/docs/csp/). Directives are passed to Helmet - see [their documentation](https://helmetjs.github.io/docs/csp/) for more information on the format. Some defaults are added to the configured values so that the application doesn't break. To disable this behaviour, set `addDefaults` to `false`. Further, if `usecdn` is on, some CDN locations are allowed too. By default (`auto`), insecure (HTTP) requests are upgraded to HTTPS via CSP if `useSSL` is on. To change this behaviour, set `upgradeInsecureRequests` to either `true` or `false`. |
224+
| `protocolUseSSL` | `true` or `false` | set to use SSL protocol for resources path (only applied when domain is set) |
225+
| `urlAddPort` | `true` or `false` | set to add port on callback URL (ports `80` or `443` won't be applied) (only applied when domain is set) |
226+
| `useCDN` | `true` or `false` | set to use CDN resources or not (default is `true`) |
227+
| `allowAnonymous` | `true` or `false` | set to allow anonymous usage (default is `true`) |
228+
| `allowAnonymousEdits` | `true` or `false` | if `allowAnonymous` is `true`: allow users to select `freely` permission, allowing guests to edit existing notes (default is `false`) |
229+
| `allowFreeURL` | `true` or `false` | set to allow new note creation by accessing a nonexistent note URL |
230+
| `defaultPermission` | `freely`, `editable`, `limited`, `locked`, `protected` or `private` | set notes default permission (only applied on signed users) |
231+
| `dbURL` | `mysql://localhost:3306/database` | set the db URL; if set, then db config (below) won't be applied |
232232
| `db` | `{ "dialect": "sqlite", "storage": "./db.hackmd.sqlite" }` | set the db configs, [see more here](http://sequelize.readthedocs.org/en/latest/api/sequelize/) |
233-
| `sslkeypath` | `./cert/client.key` | SSL key path (only need when you set `usessl`) |
234-
| `sslcertpath` | `./cert/hackmd_io.crt` | SSL cert path (only need when you set `usessl`) |
235-
| `sslcapath` | `['./cert/COMODORSAAddTrustCA.crt']` | SSL ca chain (only need when you set `usessl`) |
236-
| `dhparampath` | `./cert/dhparam.pem` | SSL dhparam path (only need when you set `usessl`) |
237-
| `tmppath` | `./tmp/` | temp directory path |
238-
| `defaultnotepath` | `./public/default.md` | default note file path |
239-
| `docspath` | `./public/docs` | docs directory path |
240-
| `indexpath` | `./public/views/index.ejs` | index template file path |
241-
| `hackmdpath` | `./public/views/hackmd.ejs` | hackmd template file path |
242-
| `errorpath` | `./public/views/error.ejs` | error template file path |
243-
| `prettypath` | `./public/views/pretty.ejs` | pretty template file path |
244-
| `slidepath` | `./public/views/slide.hbs` | slide template file path |
245-
| `sessionname` | `connect.sid` | cookie session name |
246-
| `sessionsecret` | `secret` | cookie session secret |
247-
| `sessionlife` | `14 * 24 * 60 * 60 * 1000` | cookie session life |
248-
| `staticcachetime` | `1 * 24 * 60 * 60 * 1000` | static file cache time |
249-
| `heartbeatinterval` | `5000` | socket.io heartbeat interval |
250-
| `heartbeattimeout` | `10000` | socket.io heartbeat timeout |
251-
| `documentmaxlength` | `100000` | note max length |
233+
| `sslKeyPath` | `./cert/client.key` | SSL key path (only need when you set `useSSL`) |
234+
| `sslCertPath` | `./cert/hackmd_io.crt` | SSL cert path (only need when you set `useSSL`) |
235+
| `sslCAPath` | `['./cert/COMODORSAAddTrustCA.crt']` | SSL ca chain (only need when you set `useSSL`) |
236+
| `dhParamPath` | `./cert/dhparam.pem` | SSL dhparam path (only need when you set `useSSL`) |
237+
| `tmpPath` | `./tmp/` | temp directory path |
238+
| `defaultNotePath` | `./public/default.md` | default note file path |
239+
| `docsPath` | `./public/docs` | docs directory path |
240+
| `indexPath` | `./public/views/index.ejs` | index template file path |
241+
| `hackmdPath` | `./public/views/hackmd.ejs` | hackmd template file path |
242+
| `errorPath` | `./public/views/error.ejs` | error template file path |
243+
| `prettyPath` | `./public/views/pretty.ejs` | pretty template file path |
244+
| `slidePath` | `./public/views/slide.hbs` | slide template file path |
245+
| `sessionName` | `connect.sid` | cookie session name |
246+
| `sessionSecret` | `secret` | cookie session secret |
247+
| `sessionLife` | `14 * 24 * 60 * 60 * 1000` | cookie session life |
248+
| `staticCacheTime` | `1 * 24 * 60 * 60 * 1000` | static file cache time |
249+
| `heartbeatInterval` | `5000` | socket.io heartbeat interval |
250+
| `heartbeatTimeout` | `10000` | socket.io heartbeat timeout |
251+
| `documentMaxLength` | `100000` | note max length |
252252
| `email` | `true` or `false` | set to allow email signin |
253-
| `allowemailregister` | `true` or `false` | set to allow email register (only applied when email is set, default is `true`. Note `bin/manage_users` might help you if registration is `false`.) |
254-
| `imageuploadtype` | `imgur`(default), `s3`, `minio` or `filesystem` | Where to upload image
255-
| `minio` | `{ "accessKey": "YOUR_MINIO_ACCESS_KEY", "secretKey": "YOUR_MINIO_SECRET_KEY", "endpoint": "YOUR_MINIO_HOST", port: 9000, secure: true }` | When `imageuploadtype` is set to `minio`, you need to set this key. Also checkout our [Minio Image Upload Guide](docs/guides/minio-image-upload.md) |
253+
| `allowEmailRegister` | `true` or `false` | set to allow email register (only applied when email is set, default is `true`. Note `bin/manage_users` might help you if registration is `false`.) |
254+
| `imageUploadType` | `imgur`(default), `s3`, `minio` or `filesystem` | Where to upload image
255+
| `minio` | `{ "accessKey": "YOUR_MINIO_ACCESS_KEY", "secretKey": "YOUR_MINIO_SECRET_KEY", "endpoint": "YOUR_MINIO_HOST", port: 9000, secure: true }` | When `imageUploadType` is set to `minio`, you need to set this key. Also checkout our [Minio Image Upload Guide](docs/guides/minio-image-upload.md) |
256256
| `s3` | `{ "accessKeyId": "YOUR_S3_ACCESS_KEY_ID", "secretAccessKey": "YOUR_S3_ACCESS_KEY", "region": "YOUR_S3_REGION" }` | When `imageuploadtype` be set to `s3`, you would also need to setup this key, check our [S3 Image Upload Guide](docs/guides/s3-image-upload.md) |
257-
| `s3bucket` | `YOUR_S3_BUCKET_NAME` | bucket name when `imageuploadtype` is set to `s3` or `minio` |
257+
| `s3bucket` | `YOUR_S3_BUCKET_NAME` | bucket name when `imageUploadType` is set to `s3` or `minio` |
258258

259259
## Third-party integration API key settings
260260

app.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var csp = require('./lib/csp')
3030
var constpath = path.join(__dirname, './public/js/lib/common/constant.ejs')
3131
var data = {
3232
domain: config.domain,
33-
urlpath: config.urlpath,
33+
urlpath: config.urlPath,
3434
debug: config.debug,
3535
version: config.version,
3636
GOOGLE_API_KEY: config.google.clientSecret,
@@ -47,20 +47,20 @@ ejs.renderFile(constpath, data, {}, function (err, str) {
4747
// server setup
4848
var app = express()
4949
var server = null
50-
if (config.usessl) {
50+
if (config.useSSL) {
5151
var ca = (function () {
5252
var i, len, results
5353
results = []
54-
for (i = 0, len = config.sslcapath.length; i < len; i++) {
55-
results.push(fs.readFileSync(config.sslcapath[i], 'utf8'))
54+
for (i = 0, len = config.sslCAPath.length; i < len; i++) {
55+
results.push(fs.readFileSync(config.sslCAPath[i], 'utf8'))
5656
}
5757
return results
5858
})()
5959
var options = {
60-
key: fs.readFileSync(config.sslkeypath, 'utf8'),
61-
cert: fs.readFileSync(config.sslcertpath, 'utf8'),
60+
key: fs.readFileSync(config.sslKeyPath, 'utf8'),
61+
cert: fs.readFileSync(config.sslCertPath, 'utf8'),
6262
ca: ca,
63-
dhparam: fs.readFileSync(config.dhparampath, 'utf8'),
63+
dhparam: fs.readFileSync(config.dhParamPath, 'utf8'),
6464
requestCert: false,
6565
rejectUnauthorized: false
6666
}
@@ -105,7 +105,7 @@ if (config.hsts.enable) {
105105
includeSubdomains: config.hsts.includeSubdomains,
106106
preload: config.hsts.preload
107107
}))
108-
} else if (config.usessl) {
108+
} else if (config.useSSL) {
109109
logger.info('Consider enabling HSTS for extra security:')
110110
logger.info('https://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security')
111111
}
@@ -142,17 +142,17 @@ app.use(i18n.init)
142142

143143
// routes without sessions
144144
// static files
145-
app.use('/', express.static(path.join(__dirname, '/public'), { maxAge: config.staticcachetime }))
145+
app.use('/', express.static(path.join(__dirname, '/public'), { maxAge: config.staticCacheTime }))
146146

147147
// session
148148
app.use(session({
149-
name: config.sessionname,
150-
secret: config.sessionsecret,
149+
name: config.sessionName,
150+
secret: config.sessionSecret,
151151
resave: false, // don't save session if unmodified
152152
saveUninitialized: true, // always create session to ensure the origin
153153
rolling: true, // reset maxAge on every response
154154
cookie: {
155-
maxAge: config.sessionlife
155+
maxAge: config.sessionLife
156156
},
157157
store: sessionStore
158158
}))
@@ -207,22 +207,22 @@ io.use(realtime.secure)
207207
// socket.io auth
208208
io.use(passportSocketIo.authorize({
209209
cookieParser: cookieParser,
210-
key: config.sessionname,
211-
secret: config.sessionsecret,
210+
key: config.sessionName,
211+
secret: config.sessionSecret,
212212
store: sessionStore,
213213
success: realtime.onAuthorizeSuccess,
214214
fail: realtime.onAuthorizeFail
215215
}))
216216
// socket.io heartbeat
217-
io.set('heartbeat interval', config.heartbeatinterval)
218-
io.set('heartbeat timeout', config.heartbeattimeout)
217+
io.set('heartbeat interval', config.heartbeatInterval)
218+
io.set('heartbeat timeout', config.heartbeatTimeout)
219219
// socket.io connection
220220
io.sockets.on('connection', realtime.connection)
221221

222222
// listen
223223
function startListen () {
224224
server.listen(config.port, function () {
225-
var schema = config.usessl ? 'HTTPS' : 'HTTP'
225+
var schema = config.useSSL ? 'HTTPS' : 'HTTP'
226226
logger.info('%s Server listening at port %d', schema, config.port)
227227
realtime.maintenance = false
228228
})

lib/config/default.js

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
module.exports = {
44
domain: '',
5-
urlpath: '',
5+
urlPath: '',
66
port: 3000,
7-
urladdport: false,
8-
alloworigin: ['localhost'],
9-
usessl: false,
7+
urlAddPort: false,
8+
allowOrigin: ['localhost'],
9+
useSSL: false,
1010
hsts: {
1111
enable: true,
1212
maxAgeSeconds: 31536000,
@@ -21,42 +21,40 @@ module.exports = {
2121
upgradeInsecureRequests: 'auto',
2222
reportURI: undefined
2323
},
24-
protocolusessl: false,
25-
usecdn: true,
26-
allowanonymous: true,
27-
allowanonymousedits: false,
28-
allowfreeurl: false,
29-
defaultpermission: 'editable',
30-
dburl: '',
24+
protocolUseSSL: false,
25+
useCDN: true,
26+
allowAnonymous: true,
27+
allowAnonymousEdits: false,
28+
allowFreeURL: false,
29+
defaultPermission: 'editable',
30+
dbURL: '',
3131
db: {},
3232
// ssl path
33-
sslkeypath: '',
34-
sslcertpath: '',
35-
sslcapath: '',
36-
dhparampath: '',
33+
sslKeyPath: '',
34+
sslCertPath: '',
35+
sslCAPath: '',
36+
dhParamPath: '',
3737
// other path
38-
tmppath: './tmp',
39-
defaultnotepath: './public/default.md',
40-
docspath: './public/docs',
41-
indexpath: './public/views/index.ejs',
42-
hackmdpath: './public/views/hackmd.ejs',
43-
errorpath: './public/views/error.ejs',
44-
prettypath: './public/views/pretty.ejs',
45-
slidepath: './public/views/slide.ejs',
38+
tmpPath: './tmp',
39+
defaultNotePath: './public/default.md',
40+
docsPath: './public/docs',
41+
indexPath: './public/views/index.ejs',
42+
hackmdPath: './public/views/hackmd.ejs',
43+
errorPath: './public/views/error.ejs',
44+
prettyPath: './public/views/pretty.ejs',
45+
slidePath: './public/views/slide.ejs',
4646
// session
47-
sessionname: 'connect.sid',
48-
sessionsecret: 'secret',
49-
sessionlife: 14 * 24 * 60 * 60 * 1000, // 14 days
50-
staticcachetime: 1 * 24 * 60 * 60 * 1000, // 1 day
47+
sessionName: 'connect.sid',
48+
sessionSecret: 'secret',
49+
sessionLife: 14 * 24 * 60 * 60 * 1000, // 14 days
50+
staticCacheTime: 1 * 24 * 60 * 60 * 1000, // 1 day
5151
// socket.io
52-
heartbeatinterval: 5000,
53-
heartbeattimeout: 10000,
52+
heartbeatInterval: 5000,
53+
heartbeatTimeout: 10000,
5454
// document
55-
documentmaxlength: 100000,
55+
documentMaxLength: 100000,
5656
// image upload setting, available options are imgur/s3/filesystem
57-
imageuploadtype: 'filesystem',
58-
// legacy variable name for imageuploadtype
59-
imageUploadType: undefined,
57+
imageUploadType: 'filesystem',
6058
imgur: {
6159
clientID: undefined
6260
},
@@ -133,6 +131,6 @@ module.exports = {
133131
}
134132
},
135133
email: true,
136-
allowemailregister: true,
137-
allowpdfexport: true
134+
allowEmailRegister: true,
135+
allowPDFExport: true
138136
}

lib/config/environment.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ const {toBooleanConfig, toArrayConfig, toIntegerConfig} = require('./utils')
44

55
module.exports = {
66
domain: process.env.HMD_DOMAIN,
7-
urlpath: process.env.HMD_URL_PATH,
7+
urlPath: process.env.HMD_URL_PATH,
88
port: toIntegerConfig(process.env.HMD_PORT),
9-
urladdport: toBooleanConfig(process.env.HMD_URL_ADDPORT),
10-
usessl: toBooleanConfig(process.env.HMD_USESSL),
9+
urlAddPort: toBooleanConfig(process.env.HMD_URL_ADDPORT),
10+
useSSL: toBooleanConfig(process.env.HMD_USESSL),
1111
hsts: {
1212
enable: toBooleanConfig(process.env.HMD_HSTS_ENABLE),
1313
maxAgeSeconds: process.env.HMD_HSTS_MAX_AGE,
@@ -18,15 +18,15 @@ module.exports = {
1818
enable: toBooleanConfig(process.env.HMD_CSP_ENABLE),
1919
reportURI: process.env.HMD_CSP_REPORTURI
2020
},
21-
protocolusessl: toBooleanConfig(process.env.HMD_PROTOCOL_USESSL),
22-
alloworigin: toArrayConfig(process.env.HMD_ALLOW_ORIGIN),
23-
usecdn: toBooleanConfig(process.env.HMD_USECDN),
24-
allowanonymous: toBooleanConfig(process.env.HMD_ALLOW_ANONYMOUS),
25-
allowanonymousedits: toBooleanConfig(process.env.HMD_ALLOW_ANONYMOUS_EDITS),
26-
allowfreeurl: toBooleanConfig(process.env.HMD_ALLOW_FREEURL),
27-
defaultpermission: process.env.HMD_DEFAULT_PERMISSION,
28-
dburl: process.env.HMD_DB_URL,
29-
imageuploadtype: process.env.HMD_IMAGE_UPLOAD_TYPE,
21+
protocolUseSSL: toBooleanConfig(process.env.HMD_PROTOCOL_USESSL),
22+
allowOrigin: toArrayConfig(process.env.HMD_ALLOW_ORIGIN),
23+
useCDN: toBooleanConfig(process.env.HMD_USECDN),
24+
allowAnonymous: toBooleanConfig(process.env.HMD_ALLOW_ANONYMOUS),
25+
allowAnonymousEdits: toBooleanConfig(process.env.HMD_ALLOW_ANONYMOUS_EDITS),
26+
allowFreeURL: toBooleanConfig(process.env.HMD_ALLOW_FREEURL),
27+
defaultPermission: process.env.HMD_DEFAULT_PERMISSION,
28+
dbURL: process.env.HMD_DB_URL,
29+
imageUploadType: process.env.HMD_IMAGE_UPLOAD_TYPE,
3030
imgur: {
3131
clientID: process.env.HMD_IMGUR_CLIENTID
3232
},
@@ -102,6 +102,6 @@ module.exports = {
102102
}
103103
},
104104
email: toBooleanConfig(process.env.HMD_EMAIL),
105-
allowemailregister: toBooleanConfig(process.env.HMD_ALLOW_EMAIL_REGISTER),
106-
allowpdfexport: toBooleanConfig(process.env.HMD_ALLOW_PDF_EXPORT)
105+
allowEmailRegister: toBooleanConfig(process.env.HMD_ALLOW_EMAIL_REGISTER),
106+
allowPDFExport: toBooleanConfig(process.env.HMD_ALLOW_PDF_EXPORT)
107107
}

0 commit comments

Comments
 (0)