Skip to content

Commit 967af91

Browse files
committed
feat(generators): update with-mongo & with-postgres' uri config to contain user & password
1 parent 55ee636 commit 967af91

File tree

4 files changed

+13
-16
lines changed

4 files changed

+13
-16
lines changed
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
const host = process.env.MONGO_HOST ?? 'localhost';
22
const port = +(process.env.MONGO_PORT ?? '27017');
33
const 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

77
const 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

1314
export default config;

generators/with-mongo/templates/src/db/mongo.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import config from '../config/mongo';
77
const 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,
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
const host = process.env.POSTGRES_HOST ?? 'localhost';
22
const port = +(process.env.POSTGRES_PORT ?? '5432');
33
const 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

77
const 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

1314
export default config;

generators/with-postgres/templates/src/db/postgres.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ import logger from '@boringcodes/utils/logger';
1010
import 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
1916
const connect = async (): Promise<void> => {

0 commit comments

Comments
 (0)