Reconfigura models/connection.js

This commit is contained in:
Michel Pereira 2021-10-23 14:08:47 -03:00
parent 5d9bc08322
commit 14ae4d44fe
5 changed files with 13 additions and 15 deletions

2
.gitignore vendored
View file

@ -120,7 +120,7 @@ fabric.properties
.LSOverride .LSOverride
# Icon must end with two \r # Icon must end with two \r
Icon Icon
# Thumbnails # Thumbnails
._* ._*

2
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,2 @@
{
}

View file

@ -1,29 +1,25 @@
const { MongoClient } = require('mongodb'); const { MongoClient } = require('mongodb');
require('dotenv').config();
const OPTIONS = { const OPTIONS = {
useNewUrlParser: true, useNewUrlParser: true,
useUnifiedTopology: true, useUnifiedTopology: true,
}; };
// Para usar com o avaliador:
// const MONGO_DB_URL = 'mongodb://mongodb:27017/StoreManager'; const MONGO_DB_URL = process.env.DB_URL || 'mongodb://mongodb:27017/StoreManager';
// Para uso local:
const MONGO_DB_URL = 'mongodb://localhost:27017/StoreManager';
// const DB_NAME = 'StoreManager'; // outra maneira
let db = null; let db = null;
const connection = () => (db const connection = () => (db
? Promise.resolve(db) ? Promise.resolve(db)
: MongoClient.connect(MONGO_DB_URL, OPTIONS) : MongoClient.connect(MONGO_DB_URL, OPTIONS)
.then((conn) => { .then((conn) => {
// db = conn.db(DB_NAME); // outra maneira
db = conn.db(); db = conn.db();
return db; return db;
})
.catch((err) => {
console.log(err);
process.exit(1);
})); }));
module.exports = connection; module.exports = connection;

2
package-lock.json generated
View file

@ -12,7 +12,7 @@
"@hapi/boom": "^9.1.0", "@hapi/boom": "^9.1.0",
"@hapi/joi": "^17.1.1", "@hapi/joi": "^17.1.1",
"body-parser": "^1.19.0", "body-parser": "^1.19.0",
"dotenv": "^8.2.0", "dotenv": "^8.6.0",
"express": "^4.17.1", "express": "^4.17.1",
"express-rescue": "^1.1.26", "express-rescue": "^1.1.26",
"faker": "^4.1.0", "faker": "^4.1.0",

View file

@ -23,7 +23,7 @@
"@hapi/boom": "^9.1.0", "@hapi/boom": "^9.1.0",
"@hapi/joi": "^17.1.1", "@hapi/joi": "^17.1.1",
"body-parser": "^1.19.0", "body-parser": "^1.19.0",
"dotenv": "^8.2.0", "dotenv": "^8.6.0",
"express": "^4.17.1", "express": "^4.17.1",
"express-rescue": "^1.1.26", "express-rescue": "^1.1.26",
"faker": "^4.1.0", "faker": "^4.1.0",