Skip to content

Commit dfc8aee

Browse files
committed
Add more environment variables for server configuration, update related section in README.md
1 parent 795ea21 commit dfc8aee

2 files changed

Lines changed: 59 additions & 22 deletions

File tree

README.md

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,27 @@ Environment variables (will overwrite other server configs)
101101
| variables | example values | description |
102102
| --------- | ------ | ----------- |
103103
| NODE_ENV | `production` or `development` | set current environment (will apply corresponding settings in the `config.json`) |
104-
| DOMAIN | `hackmd.io` | domain name |
105-
| URL_PATH | `hackmd` | sub url path, like `www.example.com/<URL_PATH>` |
106-
| PORT | `80` | web app port |
107104
| DEBUG | `true` or `false` | set debug mode, show more logs |
105+
| HMD_DOMAIN | `hackmd.io` | domain name |
106+
| HMD_URL_PATH | `hackmd` | sub url path, like `www.example.com/<URL_PATH>` |
107+
| HMD_PORT | `80` | web app port |
108+
| HMD_ALLOW_ORIGIN | `localhost, hackmd.io` | domain name whitelist (use comma to separate) |
109+
| HMD_PROTOCOL_USESSL | `true` or `false` | set to use ssl protocol for resources path (only applied when domain is set) |
110+
| 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) |
111+
| HMD_FACEBOOK_CLIENTID | no example | Facebook API client id |
112+
| HMD_FACEBOOK_CLIENTSECRET | no example | Facebook API client secret |
113+
| HMD_TWITTER_CONSUMERKEY | no example | Twitter API consumer key |
114+
| HMD_TWITTER_CONSUMERSECRET | no example | Twitter API consumer secret |
115+
| HMD_GITHUB_CLIENTID | no example | GitHub API client id |
116+
| HMD_GITHUB_CLIENTSECRET | no example | GitHub API client secret |
117+
| HMD_GITLAB_BASEURL | no example | GitLab authentication endpoint, set to use other endpoint than GitLab.com (optional) |
118+
| HMD_GITLAB_CLIENTID | no example | GitLab API client id |
119+
| HMD_GITLAB_CLIENTSECRET | no example | GitLab API client secret |
120+
| HMD_DROPBOX_CLIENTID | no example | Dropbox API client id |
121+
| HMD_DROPBOX_CLIENTSECRET | no example | Dropbox API client secret |
122+
| HMD_GOOGLE_CLIENTID | no example | Google API client id |
123+
| HMD_GOOGLE_CLIENTSECRET | no example | Google API client secret |
124+
| HMD_IMGUR_CLIENTID | no example | Imgur API client id |
108125

109126
Server settings `config.json`
110127
---
@@ -117,8 +134,8 @@ Server settings `config.json`
117134
| port | `80` | web app port |
118135
| alloworigin | `['localhost']` | domain name whitelist |
119136
| usessl | `true` or `false` | set to use ssl server (if true will auto turn on `protocolusessl`) |
120-
| protocolusessl | `true` or `false` | set to use ssl protocol for resources path |
121-
| urladdport | `true` or `false` | set to add port on callback url (port 80 or 443 won't applied) |
137+
| protocolusessl | `true` or `false` | set to use ssl protocol for resources path (only applied when domain is set) |
138+
| urladdport | `true` or `false` | set to add port on callback url (port 80 or 443 won't applied) (only applied when domain is set) |
122139
| usecdn | `true` or `false` | set to use CDN resources or not |
123140
| db | `{ "dialect": "sqlite", "storage": "./db.hackmd.sqlite" }` | set the db configs, [see more here](http://sequelize.readthedocs.org/en/latest/api/sequelize/) |
124141
| sslkeypath | `./cert/client.key` | ssl key path (only need when you set usessl) |
@@ -144,10 +161,10 @@ Server settings `config.json`
144161
Third-party integration api key settings
145162
---
146163

147-
| service | file path | description |
164+
| service | settings location | description |
148165
| ------- | --------- | ----------- |
149-
| facebook, twitter, github, gitlab, dropbox, google | `config.json` | for signin |
150-
| imgur | `config.json` | for image upload |
166+
| facebook, twitter, github, gitlab, dropbox, google | environment variables or `config.json` | for signin |
167+
| imgur | environment variables or `config.json` | for image upload |
151168
| google drive, dropbox | `public/js/config.js` | for export and import |
152169

153170
Third-party integration oauth callback urls

lib/config.js

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@ var config = require(path.join(__dirname, '..', 'config.json'))[env];
77
var debug = process.env.DEBUG ? (process.env.DEBUG === 'true') : ((typeof config.debug === 'boolean') ? config.debug : (env === 'development'));
88

99
// url
10-
var domain = process.env.DOMAIN || config.domain || '';
11-
var urlpath = process.env.URL_PATH || config.urlpath || '';
12-
var port = process.env.PORT || config.port || 3000;
13-
var alloworigin = config.alloworigin || ['localhost'];
10+
var domain = process.env.DOMAIN || process.env.HMD_DOMAIN || config.domain || '';
11+
var urlpath = process.env.URL_PATH || process.env.HMD_URL_PATH || config.urlpath || '';
12+
var port = process.env.PORT || process.env.HMD_PORT || config.port || 3000;
13+
var alloworigin = process.env.HMD_ALLOW_ORIGIN ? process.env.HMD_ALLOW_ORIGIN.split(',') : (config.alloworigin || ['localhost']);
1414

1515
var usessl = !!config.usessl;
16-
var protocolusessl = (config.usessl === true && typeof config.protocolusessl === 'undefined') ? true : !!config.protocolusessl;
17-
var urladdport = !!config.urladdport;
16+
var protocolusessl = (usessl === true && typeof process.env.HMD_PROTOCOL_USESSL === 'undefined' && typeof config.protocolusessl === 'undefined')
17+
? true : (process.env.HMD_PROTOCOL_USESSL ? (process.env.HMD_PROTOCOL_USESSL === 'true') : !!config.protocolusessl);
18+
var urladdport = process.env.HMD_URL_ADDPORT ? (process.env.HMD_URL_ADDPORT === 'true') : !!config.urladdport;
1819

19-
var usecdn = !!config.usecdn;
20+
var usecdn = process.env.HMD_USECDN ? (process.env.HMD_USECDN === 'true') : !!config.usecdn;
2021

2122
// db
2223
var db = config.db || {
@@ -56,13 +57,32 @@ var heartbeattimeout = config.heartbeattimeout || 5000;
5657
var documentmaxlength = config.documentmaxlength || 100000;
5758

5859
// auth
59-
var facebook = config.facebook || false;
60-
var twitter = config.twitter || false;
61-
var github = config.github || false;
62-
var gitlab = config.gitlab || false;
63-
var dropbox = config.dropbox || false;
64-
var google = config.google || false;
65-
var imgur = config.imgur || false;
60+
var facebook = (process.env.HMD_FACEBOOK_CLIENTID && process.env.HMD_FACEBOOK_CLIENTSECRET) ? {
61+
clientID: process.env.HMD_FACEBOOK_CLIENTID,
62+
clientSecret: process.env.HMD_FACEBOOK_CLIENTSECRET
63+
} : config.facebook || false;
64+
var twitter = (process.env.HMD_TWITTER_CONSUMERKEY && process.env.HMD_TWITTER_CONSUMERSECRET) ? {
65+
consumerKey: process.env.HMD_TWITTER_CONSUMERKEY,
66+
consumerSecret: process.env.HMD_TWITTER_CONSUMERSECRET
67+
} : config.twitter || false;
68+
var github = (process.env.HMD_GITHUB_CLIENTID && process.env.HMD_GITHUB_CLIENTSECRET) ? {
69+
clientID: process.env.HMD_GITHUB_CLIENTID,
70+
clientSecret: process.env.HMD_GITHUB_CLIENTSECRET
71+
} : config.github || false;
72+
var gitlab = (process.env.HMD_GITLAB_CLIENTID && process.env.HMD_GITLAB_CLIENTSECRET) ? {
73+
baseURL: process.env.HMD_GITLAB_BASEURL,
74+
clientID: process.env.HMD_GITLAB_CLIENTID,
75+
clientSecret: process.env.HMD_GITLAB_CLIENTSECRET
76+
} : config.gitlab || false;
77+
var dropbox = (process.env.HMD_DROPBOX_CLIENTID && process.env.HMD_DROPBOX_CLIENTSECRET) ? {
78+
clientID: process.env.HMD_DROPBOX_CLIENTID,
79+
clientSecret: process.env.HMD_DROPBOX_CLIENTSECRET
80+
} : config.dropbox || false;
81+
var google = (process.env.HMD_GOOGLE_CLIENTID && process.env.HMD_GOOGLE_CLIENTSECRET) ? {
82+
clientID: process.env.HMD_GOOGLE_CLIENTID,
83+
clientSecret: process.env.HMD_GOOGLE_CLIENTSECRET
84+
} : config.google || false;
85+
var imgur = process.env.HMD_IMGUR_CLIENTID || config.imgur || false;
6686

6787
function getserverurl() {
6888
var url = '';

0 commit comments

Comments
 (0)