diff options
author | abcang <abcang1015@gmail.com> | 2017-05-04 22:53:44 +0900 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2017-05-04 15:53:44 +0200 |
commit | 629a4d0fcac303a66b92d745e159a5913a38fa78 (patch) | |
tree | 2099fbe31b8f44873b569c3b1a9abf0b105030ea /streaming | |
parent | e95983f5dfe8fba7852a6ac1a42c2048e83db03d (diff) |
fix DB_URL (#2778)
Diffstat (limited to 'streaming')
-rw-r--r-- | streaming/index.js | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/streaming/index.js b/streaming/index.js index 18da58e49..883bf33f5 100644 --- a/streaming/index.js +++ b/streaming/index.js @@ -22,16 +22,30 @@ const dbUrlToConfig = (dbUrl) => { } const params = url.parse(dbUrl) - const auth = params.auth ? params.auth.split(':') : [] - - return { - user: auth[0], - password: auth[1], - host: params.hostname, - port: params.port, - database: params.pathname ? params.pathname.split('/')[1] : null, - ssl: true + const config = {} + + if (params.auth) { + [config.user, config.password] = params.auth.split(':') + } + + if (params.hostname) { + config.host = params.hostname + } + + if (params.port) { + config.port = params.port } + + if (params.pathname) { + config.database = params.params.pathname.split('/')[1] + } + + const ssl = params.query && params.query.ssl + if (ssl) { + config.ssl = ssl === 'true' || ssl === '1' + } + + return config } if (cluster.isMaster) { @@ -70,7 +84,7 @@ if (cluster.isMaster) { } const app = express() - const pgPool = new pg.Pool(Object.assign(dbUrlToConfig(process.env.DB_URL), pgConfigs[env])) + const pgPool = new pg.Pool(Object.assign(pgConfigs[env], dbUrlToConfig(process.env.DATABASE_URL))) const server = http.createServer(app) const wss = new WebSocket.Server({ server }) |