Skip to content

Commit 96fb374

Browse files
committed
Use dburl to configurate
1 parent 3a091ff commit 96fb374

3 files changed

Lines changed: 7 additions & 6 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ Environment variables (will overwrite other server configs)
120120
| HMD_USECDN | `true` or `false` | set to use CDN resources or not (default is `true`) |
121121
| HMD_ALLOW_ANONYMOUS | `true` or `false` | set to allow anonymous usage (default is `true`) |
122122
| HMD_ALLOW_FREEURL | `true` or `false` | set to allow new note by accessing not exist note url |
123+
| HMD_DB_URL | `mysql://localhost:3306/database` | set the db url |
123124
| HMD_FACEBOOK_CLIENTID | no example | Facebook API client id |
124125
| HMD_FACEBOOK_CLIENTSECRET | no example | Facebook API client secret |
125126
| HMD_TWITTER_CONSUMERKEY | no example | Twitter API consumer key |
@@ -157,6 +158,7 @@ Server settings `config.json`
157158
| usecdn | `true` or `false` | set to use CDN resources or not (default is `true`) |
158159
| allowanonymous | `true` or `false` | set to allow anonymous usage (default is `true`) |
159160
| allowfreeurl | `true` or `false` | set to allow new note by accessing not exist note url |
161+
| dburl | `mysql://localhost:3306/database` | set the db url, if set this variable then below db config won't be applied |
160162
| db | `{ "dialect": "sqlite", "storage": "./db.hackmd.sqlite" }` | set the db configs, [see more here](http://sequelize.readthedocs.org/en/latest/api/sequelize/) |
161163
| sslkeypath | `./cert/client.key` | ssl key path (only need when you set usessl) |
162164
| sslcertpath | `./cert/hackmd_io.crt` | ssl cert path (only need when you set usessl) |

lib/config.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@ var allowanonymous = process.env.HMD_ALLOW_ANONYMOUS ? (process.env.HMD_ALLOW_AN
2424
var allowfreeurl = process.env.HMD_ALLOW_FREEURL ? (process.env.HMD_ALLOW_FREEURL === 'true') : !!config.allowfreeurl;
2525

2626
// db
27-
var db = config.db || {
28-
dialect: 'sqlite',
29-
storage: './db.hackmd.sqlite'
30-
};
27+
var dburl = config.dburl || process.env.HMD_DB_URL || process.env.DATABASE_URL;
28+
var db = config.db || {};
3129

3230
// ssl path
3331
var sslkeypath = config.sslkeypath || '';
@@ -131,6 +129,7 @@ module.exports = {
131129
usecdn: usecdn,
132130
allowanonymous: allowanonymous,
133131
allowfreeurl: allowfreeurl,
132+
dburl: dburl,
134133
db: db,
135134
sslkeypath: path.join(cwd, sslkeypath),
136135
sslcertpath: path.join(cwd, sslcertpath),

lib/models/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ dbconfig.logging = config.debug ? logger.info : false;
1515
var sequelize = null;
1616

1717
// Heroku specific
18-
if (process.env.DATABASE_URL)
19-
sequelize = new Sequelize(process.env.DATABASE_URL);
18+
if (config.dburl)
19+
sequelize = new Sequelize(config.dburl, dbconfig);
2020
else
2121
sequelize = new Sequelize(dbconfig.database, dbconfig.username, dbconfig.password, dbconfig);
2222

0 commit comments

Comments
 (0)