diff options
author | Wu Cheng-Han | 2016-10-10 21:16:58 +0800 |
---|---|---|
committer | Wu Cheng-Han | 2016-10-10 21:16:58 +0800 |
commit | dfc8aeeba07966bc1ea116e20e3b2d0af27f6c47 (patch) | |
tree | 5ccb209fa32fd680be39baf0ec833ee3adafe29b | |
parent | 795ea21191486a80437d7c535defc503962c5968 (diff) |
Add more environment variables for server configuration, update related section in README.md
Diffstat (limited to '')
-rw-r--r-- | README.md | 33 | ||||
-rw-r--r-- | lib/config.js | 48 |
2 files changed, 59 insertions, 22 deletions
@@ -101,10 +101,27 @@ Environment variables (will overwrite other server configs) | variables | example values | description | | --------- | ------ | ----------- | | NODE_ENV | `production` or `development` | set current environment (will apply corresponding settings in the `config.json`) | -| DOMAIN | `hackmd.io` | domain name | -| URL_PATH | `hackmd` | sub url path, like `www.example.com/<URL_PATH>` | -| PORT | `80` | web app port | | DEBUG | `true` or `false` | set debug mode, show more logs | +| HMD_DOMAIN | `hackmd.io` | domain name | +| HMD_URL_PATH | `hackmd` | sub url path, like `www.example.com/<URL_PATH>` | +| HMD_PORT | `80` | web app port | +| HMD_ALLOW_ORIGIN | `localhost, hackmd.io` | domain name whitelist (use comma to separate) | +| HMD_PROTOCOL_USESSL | `true` or `false` | set to use ssl protocol for resources path (only applied when domain is set) | +| HMD_URL_ADDPORT | `true` or `false` | set to add port on callback url (port 80 or 443 won't applied) (only applied when domain is set) | +| HMD_FACEBOOK_CLIENTID | no example | Facebook API client id | +| HMD_FACEBOOK_CLIENTSECRET | no example | Facebook API client secret | +| HMD_TWITTER_CONSUMERKEY | no example | Twitter API consumer key | +| HMD_TWITTER_CONSUMERSECRET | no example | Twitter API consumer secret | +| HMD_GITHUB_CLIENTID | no example | GitHub API client id | +| HMD_GITHUB_CLIENTSECRET | no example | GitHub API client secret | +| HMD_GITLAB_BASEURL | no example | GitLab authentication endpoint, set to use other endpoint than GitLab.com (optional) | +| HMD_GITLAB_CLIENTID | no example | GitLab API client id | +| HMD_GITLAB_CLIENTSECRET | no example | GitLab API client secret | +| HMD_DROPBOX_CLIENTID | no example | Dropbox API client id | +| HMD_DROPBOX_CLIENTSECRET | no example | Dropbox API client secret | +| HMD_GOOGLE_CLIENTID | no example | Google API client id | +| HMD_GOOGLE_CLIENTSECRET | no example | Google API client secret | +| HMD_IMGUR_CLIENTID | no example | Imgur API client id | Server settings `config.json` --- @@ -117,8 +134,8 @@ Server settings `config.json` | port | `80` | web app port | | alloworigin | `['localhost']` | domain name whitelist | | usessl | `true` or `false` | set to use ssl server (if true will auto turn on `protocolusessl`) | -| protocolusessl | `true` or `false` | set to use ssl protocol for resources path | -| urladdport | `true` or `false` | set to add port on callback url (port 80 or 443 won't applied) | +| protocolusessl | `true` or `false` | set to use ssl protocol for resources path (only applied when domain is set) | +| urladdport | `true` or `false` | set to add port on callback url (port 80 or 443 won't applied) (only applied when domain is set) | | usecdn | `true` or `false` | set to use CDN resources or not | | db | `{ "dialect": "sqlite", "storage": "./db.hackmd.sqlite" }` | set the db configs, [see more here](http://sequelize.readthedocs.org/en/latest/api/sequelize/) | | sslkeypath | `./cert/client.key` | ssl key path (only need when you set usessl) | @@ -144,10 +161,10 @@ Server settings `config.json` Third-party integration api key settings --- -| service | file path | description | +| service | settings location | description | | ------- | --------- | ----------- | -| facebook, twitter, github, gitlab, dropbox, google | `config.json` | for signin | -| imgur | `config.json` | for image upload | +| facebook, twitter, github, gitlab, dropbox, google | environment variables or `config.json` | for signin | +| imgur | environment variables or `config.json` | for image upload | | google drive, dropbox | `public/js/config.js` | for export and import | Third-party integration oauth callback urls diff --git a/lib/config.js b/lib/config.js index 588128a7..46afea9e 100644 --- a/lib/config.js +++ b/lib/config.js @@ -7,16 +7,17 @@ var config = require(path.join(__dirname, '..', 'config.json'))[env]; var debug = process.env.DEBUG ? (process.env.DEBUG === 'true') : ((typeof config.debug === 'boolean') ? config.debug : (env === 'development')); // url -var domain = process.env.DOMAIN || config.domain || ''; -var urlpath = process.env.URL_PATH || config.urlpath || ''; -var port = process.env.PORT || config.port || 3000; -var alloworigin = config.alloworigin || ['localhost']; +var domain = process.env.DOMAIN || process.env.HMD_DOMAIN || config.domain || ''; +var urlpath = process.env.URL_PATH || process.env.HMD_URL_PATH || config.urlpath || ''; +var port = process.env.PORT || process.env.HMD_PORT || config.port || 3000; +var alloworigin = process.env.HMD_ALLOW_ORIGIN ? process.env.HMD_ALLOW_ORIGIN.split(',') : (config.alloworigin || ['localhost']); var usessl = !!config.usessl; -var protocolusessl = (config.usessl === true && typeof config.protocolusessl === 'undefined') ? true : !!config.protocolusessl; -var urladdport = !!config.urladdport; +var protocolusessl = (usessl === true && typeof process.env.HMD_PROTOCOL_USESSL === 'undefined' && typeof config.protocolusessl === 'undefined') + ? true : (process.env.HMD_PROTOCOL_USESSL ? (process.env.HMD_PROTOCOL_USESSL === 'true') : !!config.protocolusessl); +var urladdport = process.env.HMD_URL_ADDPORT ? (process.env.HMD_URL_ADDPORT === 'true') : !!config.urladdport; -var usecdn = !!config.usecdn; +var usecdn = process.env.HMD_USECDN ? (process.env.HMD_USECDN === 'true') : !!config.usecdn; // db var db = config.db || { @@ -56,13 +57,32 @@ var heartbeattimeout = config.heartbeattimeout || 5000; var documentmaxlength = config.documentmaxlength || 100000; // auth -var facebook = config.facebook || false; -var twitter = config.twitter || false; -var github = config.github || false; -var gitlab = config.gitlab || false; -var dropbox = config.dropbox || false; -var google = config.google || false; -var imgur = config.imgur || false; +var facebook = (process.env.HMD_FACEBOOK_CLIENTID && process.env.HMD_FACEBOOK_CLIENTSECRET) ? { + clientID: process.env.HMD_FACEBOOK_CLIENTID, + clientSecret: process.env.HMD_FACEBOOK_CLIENTSECRET +} : config.facebook || false; +var twitter = (process.env.HMD_TWITTER_CONSUMERKEY && process.env.HMD_TWITTER_CONSUMERSECRET) ? { + consumerKey: process.env.HMD_TWITTER_CONSUMERKEY, + consumerSecret: process.env.HMD_TWITTER_CONSUMERSECRET +} : config.twitter || false; +var github = (process.env.HMD_GITHUB_CLIENTID && process.env.HMD_GITHUB_CLIENTSECRET) ? { + clientID: process.env.HMD_GITHUB_CLIENTID, + clientSecret: process.env.HMD_GITHUB_CLIENTSECRET +} : config.github || false; +var gitlab = (process.env.HMD_GITLAB_CLIENTID && process.env.HMD_GITLAB_CLIENTSECRET) ? { + baseURL: process.env.HMD_GITLAB_BASEURL, + clientID: process.env.HMD_GITLAB_CLIENTID, + clientSecret: process.env.HMD_GITLAB_CLIENTSECRET +} : config.gitlab || false; +var dropbox = (process.env.HMD_DROPBOX_CLIENTID && process.env.HMD_DROPBOX_CLIENTSECRET) ? { + clientID: process.env.HMD_DROPBOX_CLIENTID, + clientSecret: process.env.HMD_DROPBOX_CLIENTSECRET +} : config.dropbox || false; +var google = (process.env.HMD_GOOGLE_CLIENTID && process.env.HMD_GOOGLE_CLIENTSECRET) ? { + clientID: process.env.HMD_GOOGLE_CLIENTID, + clientSecret: process.env.HMD_GOOGLE_CLIENTSECRET +} : config.google || false; +var imgur = process.env.HMD_IMGUR_CLIENTID || config.imgur || false; function getserverurl() { var url = ''; |