From acaeef172a96f613704a08c5fdc0d192be9eab31 Mon Sep 17 00:00:00 2001 From: bananaappletw Date: Thu, 22 Dec 2016 13:23:17 +0800 Subject: Fix #293 --- lib/models/index.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/models/index.js b/lib/models/index.js index d52f5508..1156d0f7 100644 --- a/lib/models/index.js +++ b/lib/models/index.js @@ -13,10 +13,11 @@ var dbconfig = config.db; dbconfig.logging = config.debug ? logger.info : false; var sequelize = null; -if (dbconfig.hasOwnProperty('username') || dbconfig.hasOwnProperty('password')) - sequelize = new Sequelize(dbconfig.database, dbconfig.username, dbconfig.password, dbconfig); + +if (process.env.DATABASE_URL) + sequelize = new Sequelize(process.env.DATABASE_URL, dbconfig.username, dbconfig.password, dbconfig); else - sequelize = new Sequelize(dbconfig.database, dbconfig); + sequelize = new Sequelize(dbconfig.database, dbconfig.username, dbconfig.password, dbconfig); var db = {}; -- cgit v1.2.3 From 936d922442faa5c60d6831cd350c0fc885e32bcb Mon Sep 17 00:00:00 2001 From: bananaappletw Date: Thu, 22 Dec 2016 15:28:44 +0800 Subject: Remove unnecessary db config of heroku --- bin/heroku | 6 ------ 1 file changed, 6 deletions(-) diff --git a/bin/heroku b/bin/heroku index 0375e9e7..6ee7fa41 100755 --- a/bin/heroku +++ b/bin/heroku @@ -23,12 +23,6 @@ EOF { "production": { - "db": { - "database": "${DATABASE_URL}", - "dialectOptions": { - "ssl": true - } - } } } -- cgit v1.2.3 From 3a091ff9a52e510c362ad57cc816599b8ae2b53a Mon Sep 17 00:00:00 2001 From: bananaappletw Date: Thu, 22 Dec 2016 19:42:00 +0800 Subject: Simplify code for heroku --- lib/models/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/models/index.js b/lib/models/index.js index 1156d0f7..6fcffb5f 100644 --- a/lib/models/index.js +++ b/lib/models/index.js @@ -14,8 +14,9 @@ dbconfig.logging = config.debug ? logger.info : false; var sequelize = null; +// Heroku specific if (process.env.DATABASE_URL) - sequelize = new Sequelize(process.env.DATABASE_URL, dbconfig.username, dbconfig.password, dbconfig); + sequelize = new Sequelize(process.env.DATABASE_URL); else sequelize = new Sequelize(dbconfig.database, dbconfig.username, dbconfig.password, dbconfig); -- cgit v1.2.3 From 96fb3743f31acca0c6b272de3e8656384c2cda89 Mon Sep 17 00:00:00 2001 From: bananaappletw Date: Thu, 22 Dec 2016 21:20:43 +0800 Subject: Use dburl to configurate --- README.md | 2 ++ lib/config.js | 7 +++---- lib/models/index.js | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 406986a5..a9270fb2 100644 --- a/README.md +++ b/README.md @@ -120,6 +120,7 @@ Environment variables (will overwrite other server configs) | HMD_USECDN | `true` or `false` | set to use CDN resources or not (default is `true`) | | HMD_ALLOW_ANONYMOUS | `true` or `false` | set to allow anonymous usage (default is `true`) | | HMD_ALLOW_FREEURL | `true` or `false` | set to allow new note by accessing not exist note url | +| HMD_DB_URL | `mysql://localhost:3306/database` | set the db url | | 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 | @@ -157,6 +158,7 @@ Server settings `config.json` | usecdn | `true` or `false` | set to use CDN resources or not (default is `true`) | | allowanonymous | `true` or `false` | set to allow anonymous usage (default is `true`) | | allowfreeurl | `true` or `false` | set to allow new note by accessing not exist note url | +| dburl | `mysql://localhost:3306/database` | set the db url, if set this variable then below db config won't be applied | | 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) | | sslcertpath | `./cert/hackmd_io.crt` | ssl cert path (only need when you set usessl) | diff --git a/lib/config.js b/lib/config.js index 9e8aa337..f8df0a73 100644 --- a/lib/config.js +++ b/lib/config.js @@ -24,10 +24,8 @@ var allowanonymous = process.env.HMD_ALLOW_ANONYMOUS ? (process.env.HMD_ALLOW_AN var allowfreeurl = process.env.HMD_ALLOW_FREEURL ? (process.env.HMD_ALLOW_FREEURL === 'true') : !!config.allowfreeurl; // db -var db = config.db || { - dialect: 'sqlite', - storage: './db.hackmd.sqlite' -}; +var dburl = config.dburl || process.env.HMD_DB_URL || process.env.DATABASE_URL; +var db = config.db || {}; // ssl path var sslkeypath = config.sslkeypath || ''; @@ -131,6 +129,7 @@ module.exports = { usecdn: usecdn, allowanonymous: allowanonymous, allowfreeurl: allowfreeurl, + dburl: dburl, db: db, sslkeypath: path.join(cwd, sslkeypath), sslcertpath: path.join(cwd, sslcertpath), diff --git a/lib/models/index.js b/lib/models/index.js index 6fcffb5f..de6cd13c 100644 --- a/lib/models/index.js +++ b/lib/models/index.js @@ -15,8 +15,8 @@ dbconfig.logging = config.debug ? logger.info : false; var sequelize = null; // Heroku specific -if (process.env.DATABASE_URL) - sequelize = new Sequelize(process.env.DATABASE_URL); +if (config.dburl) + sequelize = new Sequelize(config.dburl, dbconfig); else sequelize = new Sequelize(dbconfig.database, dbconfig.username, dbconfig.password, dbconfig); -- cgit v1.2.3 From c58f28a9d43804018c94fd2899b50863f1b5a2b6 Mon Sep 17 00:00:00 2001 From: bananaappletw Date: Thu, 22 Dec 2016 22:03:04 +0800 Subject: Add sqlite for test environment --- config.json.example | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/config.json.example b/config.json.example index 22fd5c92..7e4ac0b7 100644 --- a/config.json.example +++ b/config.json.example @@ -1,4 +1,8 @@ { + "test": { + "dialect": "sqlite", + "storage": "./db.hackmd.sqlite" + }, "development": { "domain": "localhost", "db": { -- cgit v1.2.3