File tree Expand file tree Collapse file tree 4 files changed +13
-16
lines changed
with-postgres/templates/src Expand file tree Collapse file tree 4 files changed +13
-16
lines changed Original file line number Diff line number Diff line change 11const host = process . env . MONGO_HOST ?? 'localhost' ;
22const port = + ( process . env . MONGO_PORT ?? '27017' ) ;
33const dbName = process . env . MONGO_DB_NAME ?? '<%= elementName %>' ;
4- const user = process . env . MONGO_USER ;
5- const password = process . env . MONGO_PASSWORD ;
4+ const user = process . env . MONGO_USER ?? '' ;
5+ const password = process . env . MONGO_PASSWORD ?? '' ;
66
77const config = {
8- uri : `mongodb://${ host } :${ port } /${ dbName } ` ,
9- user,
10- password,
8+ uri :
9+ user === '' || password === ''
10+ ? `mongodb://${ host } :${ port } /${ dbName } `
11+ : `mongodb://${ user } :${ password } @${ host } :${ port } /${ dbName } ` ,
1112} ;
1213
1314export default config ;
Original file line number Diff line number Diff line change @@ -7,8 +7,6 @@ import config from '../config/mongo';
77const connect = async ( ) : Promise < void > => {
88 try {
99 await mongoose . connect ( config . uri , {
10- user : config . user ,
11- pass : config . password ,
1210 useUnifiedTopology : true ,
1311 useNewUrlParser : true ,
1412 promiseLibrary : Promise ,
Original file line number Diff line number Diff line change 11const host = process . env . POSTGRES_HOST ?? 'localhost' ;
22const port = + ( process . env . POSTGRES_PORT ?? '5432' ) ;
33const dbName = process . env . POSTGRES_DB_NAME ?? '<%= elementName %>' ;
4- const user = process . env . POSTGRES_USER ;
5- const password = process . env . POSTGRES_PASSWORD ;
4+ const user = process . env . POSTGRES_USER ?? '' ;
5+ const password = process . env . POSTGRES_PASSWORD ?? '' ;
66
77const config = {
8- uri : `postgres://${ host } :${ port } /${ dbName } ` ,
9- user,
10- password,
8+ uri :
9+ user === '' || password === ''
10+ ? `postgres://${ host } :${ port } /${ dbName } `
11+ : `postgres://${ user } :${ password } @${ host } :${ port } /${ dbName } ` ,
1112} ;
1213
1314export default config ;
Original file line number Diff line number Diff line change @@ -10,10 +10,7 @@ import logger from '@boringcodes/utils/logger';
1010import config from '../config/postgres' ;
1111
1212// create sequelize
13- const sequelize = new Sequelize ( config . uri , {
14- username : config . user ,
15- password : config . password ,
16- } ) ;
13+ const sequelize = new Sequelize ( config . uri ) ;
1714
1815// connect postgres
1916const connect = async ( ) : Promise < void > => {
You can’t perform that action at this time.
0 commit comments