Skip to content

Commit 8cf849e

Browse files
authored
Merge pull request #294 from bananaappletw/master
Fix #293
2 parents 8153fa3 + c58f28a commit 8cf849e

5 files changed

Lines changed: 14 additions & 13 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) |

bin/heroku

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ EOF
2323
2424
{
2525
"production": {
26-
"db": {
27-
"database": "${DATABASE_URL}",
28-
"dialectOptions": {
29-
"ssl": true
30-
}
31-
}
3226
}
3327
}
3428

config.json.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
{
2+
"test": {
3+
"dialect": "sqlite",
4+
"storage": "./db.hackmd.sqlite"
5+
},
26
"development": {
37
"domain": "localhost",
48
"db": {

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: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ var dbconfig = config.db;
1313
dbconfig.logging = config.debug ? logger.info : false;
1414

1515
var sequelize = null;
16-
if (dbconfig.hasOwnProperty('username') || dbconfig.hasOwnProperty('password'))
17-
sequelize = new Sequelize(dbconfig.database, dbconfig.username, dbconfig.password, dbconfig);
16+
17+
// Heroku specific
18+
if (config.dburl)
19+
sequelize = new Sequelize(config.dburl, dbconfig);
1820
else
19-
sequelize = new Sequelize(dbconfig.database, dbconfig);
21+
sequelize = new Sequelize(dbconfig.database, dbconfig.username, dbconfig.password, dbconfig);
2022

2123
var db = {};
2224

0 commit comments

Comments
 (0)