File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -31,7 +31,9 @@ Config.prototype = {
3131} ;
3232
3333exports . load = function ( config , currentEnv ) {
34- if ( typeof config === 'object' ) {
34+ if ( process . env . DATABASE_URL ) {
35+ return exports . loadUrl ( process . env . DATABASE_URL , currentEnv ) ;
36+ } else if ( typeof config === 'object' ) {
3537 return exports . loadObject ( config , currentEnv ) ;
3638 } else {
3739 return exports . loadFile ( config , currentEnv ) ;
Original file line number Diff line number Diff line change @@ -308,6 +308,28 @@ lab.experiment('config', function () {
308308 }
309309 ) ;
310310
311+ lab . experiment ( 'loading a url from the DATABASE_URL environment variable' , function ( ) {
312+ lab . test ( 'should use DATABASE_URL env var in lue of anything else' , function ( done , cleanup ) {
313+ process . env . DATABASE_URL = 'postgres://uname:pw@server.com/dbname' ;
314+ var configPath = path . join ( __dirname , 'database_with_default_env.json' ) ;
315+ var cfg = config . load ( configPath , 'dev' ) ;
316+ cleanup ( function ( next ) {
317+ delete process . env . DATABASE_URL ;
318+ next ( ) ;
319+ } ) ;
320+
321+ Code . expect ( cfg . getCurrent ) . to . exists ( ) ;
322+ var current = cfg . getCurrent ( ) ;
323+ Code . expect ( current . env ) . to . equal ( 'dev' ) ;
324+ Code . expect ( current . settings . driver ) . to . equal ( 'postgres' ) ;
325+ Code . expect ( current . settings . user ) . to . equal ( 'uname' ) ;
326+ Code . expect ( current . settings . password ) . to . equal ( 'pw' ) ;
327+ Code . expect ( current . settings . database ) . to . equal ( 'dbname' ) ;
328+ Code . expect ( current . settings . host ) . to . equal ( 'server.com' ) ;
329+ done ( ) ;
330+ } ) ;
331+ } ) ;
332+
311333 lab . experiment (
312334 'loading from an ENV URL within the object and extending it from the ENV' ,
313335 function ( ) {
You can’t perform that action at this time.
0 commit comments