Skip to content
Snippets Groups Projects
Commit cdcb177f authored by Markus Klose's avatar Markus Klose
Browse files

MongoDB Zero Trust User

parent f906c123
Branches
No related tags found
1 merge request!10Skalierbarkeit
...@@ -150,8 +150,14 @@ services: ...@@ -150,8 +150,14 @@ services:
- 27017:27017 - 27017:27017
volumes: volumes:
- mongodb:/data/db - mongodb:/data/db
logging: environment:
driver: none #MONGO_INITDB_ROOT_USERNAME: admin
#MONGO_INITDB_ROOT_PASSWORD: adminpassword
- ADMINUSER=ccadmin
- ADMINPASSWORD=abc123
command:
- "--auth"
# node: # node:
# restart: always # restart: always
......
...@@ -4,7 +4,7 @@ const app = express(); ...@@ -4,7 +4,7 @@ const app = express();
const http = require('http'); const http = require('http');
const https = require('https'); const https = require('https');
const fs = require('fs'); const fs = require('fs');
const { mongo, default: mongoose } = require('mongoose'); const { mongo, default: mongoose, MongooseError } = require('mongoose');
//http Server //http Server
const server = http.createServer(app); const server = http.createServer(app);
...@@ -55,8 +55,10 @@ app.use(cors()); ...@@ -55,8 +55,10 @@ app.use(cors());
//mongoose.connect("mongodb://mongodb:27017/cloudComputing"); //mongoose.connect("mongodb://mongodb:27017/cloudComputing");
const connectWithRetry = () => { const connectWithRetry = () => {
let username = process.env.ADMINUSER;
let password = process.env.ADMINPASSWORD;
mongoose mongoose
.connect('mongodb://mongodb:27017/cloudComputing', {useNewUrlParser: true}) .connect('mongodb://ccadmin:abc123@mongodb:27017/cloudComputing', {useNewUrlParser: true})
.then(() => console.log("successfully connected to DB")) .then(() => console.log("successfully connected to DB"))
.then(serverListen()) .then(serverListen())
.catch((e) => { .catch((e) => {
...@@ -65,6 +67,8 @@ const connectWithRetry = () => { ...@@ -65,6 +67,8 @@ const connectWithRetry = () => {
}); });
}; };
connectWithRetry(); connectWithRetry();
//Prometheus //Prometheus
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment