From ab767b2139d7d4580b2485222700badf7594c1f7 Mon Sep 17 00:00:00 2001
From: unknown
Date: Fri, 7 Nov 2014 17:53:02 -0800
Subject: [PATCH 1/6] update node and npm version to the latest supported in
Azure Websites
---
package.json | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/package.json b/package.json
index 9eb6785..db6b3d3 100644
--- a/package.json
+++ b/package.json
@@ -9,7 +9,7 @@
"socket.io": "0.9.10"
},
"engines": {
- "node": "0.8.4",
- "npm": "1.1.49"
+ "node": "0.10.32",
+ "npm": "1.4.9"
}
}
From c4ecf492475dd9c3a314845794a3633dfb70502c Mon Sep 17 00:00:00 2001
From: unknown
Date: Fri, 14 Nov 2014 21:01:56 -0800
Subject: [PATCH 2/6] point to mongo db vm
---
package.json | 3 ++-
routes/wines.js | 2 +-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/package.json b/package.json
index db6b3d3..954a121 100644
--- a/package.json
+++ b/package.json
@@ -6,7 +6,8 @@
"dependencies": {
"express": "3.x",
"mongodb": "1.1.8",
- "socket.io": "0.9.10"
+ "socket.io": "0.9.10",
+ "mongoose" : "3.8.12"
},
"engines": {
"node": "0.10.32",
diff --git a/routes/wines.js b/routes/wines.js
index 1626db8..cfbc070 100644
--- a/routes/wines.js
+++ b/routes/wines.js
@@ -4,7 +4,7 @@ var Server = mongo.Server,
Db = mongo.Db,
BSON = mongo.BSONPure;
-var server = new Server('localhost', 27017, {auto_reconnect: true});
+var server = new Server('mongodb-f4h7y436.cloudapp.net', 27017, {auto_reconnect: true});
db = new Db('winedb', server, {safe: true});
db.open(function(err, db) {
From 4213ddb42c283f83cdd69a4c93275a98442c953b Mon Sep 17 00:00:00 2001
From: unknown
Date: Mon, 17 Nov 2014 17:55:44 -0800
Subject: [PATCH 3/6] connect properly to MongoDB in Azure VM IAAS
---
readme.md | 32 ++++++--------------------------
routes/wines.js | 39 +++++++++++++++++++++++++++++++++++++--
setup/SetupDB.js | 10 ++++++++++
setup/mongod.cfg | 9 +++++++++
setup/readme.md | 14 ++++++++++++++
5 files changed, 76 insertions(+), 28 deletions(-)
create mode 100644 setup/SetupDB.js
create mode 100644 setup/mongod.cfg
create mode 100644 setup/readme.md
diff --git a/readme.md b/readme.md
index 8732ef1..60cb53b 100644
--- a/readme.md
+++ b/readme.md
@@ -9,29 +9,9 @@ This application is further documented [here](http://coenraets.org/blog).
The application is also hosted online. You can test it [here](http://nodecellar.coenraets.org).
-## To run the application on your own Heroku account:##
-
-1. Install the [Heroku Toolbelt](http://toolbelt.heroku.com)
-
-2. [Sign up](http://heroku.com/signup) for a Heroku account
-
-3. Login to Heroku from the `heroku` CLI:
-
- $ heroku login
-
-4. Create a new app on Heroku:
-
- $ heroku create
-
-5. Add the [MongoLab Heroku Add-on](http://addons.heroku.com/mongolab)
-
- $ heroku addons:add mongolab
-
-6. Upload the app to Heroku:
-
- $ git push heroku master
-
-7. Open the app in your browser:
-
- $ heroku open
-
+## To run the application on your own Azure account:##
+1. Setup mongo db to Azure VM - see setup folder for hints
+2. In Azure websites create App settings:
+ a. MongoDbUserName with username to wine database
+ b. MongoDbPassword - password for the user with readWrite access
+ c. TODO create variable for the server
\ No newline at end of file
diff --git a/routes/wines.js b/routes/wines.js
index cfbc070..7acc4df 100644
--- a/routes/wines.js
+++ b/routes/wines.js
@@ -1,11 +1,46 @@
var mongo = require('mongodb');
+console.log('Connecting to wine database... ');
+
var Server = mongo.Server,
Db = mongo.Db,
BSON = mongo.BSONPure;
+
+var server = new mongo.Server('mongodb-f4h7y436.cloudapp.net', 27017, {
+ auto_reconnect: true
+ }),
+ db = new mongo.Db('wine', server),
+ usename = process.env.MongoDbUserName,
+ password = process.env.MongoDbPassword;
+
+// callback: (err, db)
+function openDatabase(callback) {
+ db.open(function(err, db) {
+ if (err)
+ return callback(err);
+
+ console.log('Database connected');
+
+ return callback(null, db);
+ });
+}
-var server = new Server('mongodb-f4h7y436.cloudapp.net', 27017, {auto_reconnect: true});
-db = new Db('winedb', server, {safe: true});
+// callback: (err, collection)
+function authenticate(db1, username, password, callback) {
+ db1.authenticate(username, password, function(err, result) {
+ if (err) {
+ return callback (err);
+ }
+ if (result) {
+ var collection = new mongo.Collection(db1, 'wines');
+
+ // always, ALWAYS return the error object as the first argument of a callback
+ return callback(null, collection);
+ } else {
+ return callback (new Error('authentication failed'));
+ }
+ });
+}
db.open(function(err, db) {
if(!err) {
diff --git a/setup/SetupDB.js b/setup/SetupDB.js
new file mode 100644
index 0000000..2f583e9
--- /dev/null
+++ b/setup/SetupDB.js
@@ -0,0 +1,10 @@
+use wine
+db.createUser(
+ {
+ user: "wineUser",
+ pwd: "1XXXXXXX",
+ roles: [
+ { role: "readWrite", db: "wine" },
+ ]
+ }
+)
\ No newline at end of file
diff --git a/setup/mongod.cfg b/setup/mongod.cfg
new file mode 100644
index 0000000..a386118
--- /dev/null
+++ b/setup/mongod.cfg
@@ -0,0 +1,9 @@
+systemLog:
+ destination: file
+ path: "/mongodb/mongodb.log"
+ logAppend: true
+storage:
+ journal:
+ enabled: true
+net:
+ port: 27017
\ No newline at end of file
diff --git a/setup/readme.md b/setup/readme.md
new file mode 100644
index 0000000..6b8ef15
--- /dev/null
+++ b/setup/readme.md
@@ -0,0 +1,14 @@
+Useful links
+
+Install windows service
+.\bin\mongod.exe --config "C:\mongodb\mongod.cfg" --install
+
+Useful links
+http://docs.mongodb.org/manual/tutorial/install-mongodb-on-windows/
+http://docs.mongodb.org/manual/reference/configuration-options/
+http://docs.mongodb.org/manual/tutorial/change-user-privileges/
+http://stackoverflow.com/questions/4870328/how-to-read-environment-variable-in-node-js
+http://stackoverflow.com/questions/10108170/node-js-reuse-mongodb-reference
+
+To setup db user see SetupDb.js
+
From 3f64ce077d9d9f845335d703d2bbc556ac04e225 Mon Sep 17 00:00:00 2001
From: unknown
Date: Fri, 21 Nov 2014 06:09:39 -0800
Subject: [PATCH 4/6] Expose server name as environment variable. Add more
logging
---
readme.md | 3 ++-
routes/wines.js | 15 ++++++++++-----
setup/SetupDB.js | 4 ++++
setup/readme.md | 11 +++++++++++
4 files changed, 27 insertions(+), 6 deletions(-)
diff --git a/readme.md b/readme.md
index 60cb53b..5979a2b 100644
--- a/readme.md
+++ b/readme.md
@@ -12,6 +12,7 @@ The application is also hosted online. You can test it [here](http://nodecellar.
## To run the application on your own Azure account:##
1. Setup mongo db to Azure VM - see setup folder for hints
2. In Azure websites create App settings:
- a. MongoDbUserName with username to wine database
+ a. MongoDbServer with DNS for the MongoDb which listens on port 27017
+ a. MongoDbUserName with username to wine database - default user is wineUser
b. MongoDbPassword - password for the user with readWrite access
c. TODO create variable for the server
\ No newline at end of file
diff --git a/routes/wines.js b/routes/wines.js
index 7acc4df..88afc28 100644
--- a/routes/wines.js
+++ b/routes/wines.js
@@ -1,17 +1,20 @@
var mongo = require('mongodb');
-console.log('Connecting to wine database... ');
var Server = mongo.Server,
Db = mongo.Db,
BSON = mongo.BSONPure;
-var server = new mongo.Server('mongodb-f4h7y436.cloudapp.net', 27017, {
+var serverName = process.env.MongoDbServer || 'galini-mongodb.cloudapp.net',
+ usename = process.env.MongoDbUserName || 'wineUser',
+ password = process.env.MongoDbPassword;
+
+console.log('Connecting to wine database on ' + serverName + ' with user ' + usename + '... ');
+
+var server = new mongo.Server(serverName, 27017, {
auto_reconnect: true
}),
- db = new mongo.Db('wine', server),
- usename = process.env.MongoDbUserName,
- password = process.env.MongoDbPassword;
+ db = new mongo.Db('wine', server);
// callback: (err, db)
function openDatabase(callback) {
@@ -51,6 +54,8 @@ db.open(function(err, db) {
populateDB();
}
});
+ } else {
+ console.log("Error while connecting to database " + JSON.stringify(err));
}
});
diff --git a/setup/SetupDB.js b/setup/SetupDB.js
index 2f583e9..0866af0 100644
--- a/setup/SetupDB.js
+++ b/setup/SetupDB.js
@@ -1,3 +1,7 @@
+
+Run .\bin\mongo --port 27017
+
+
use wine
db.createUser(
{
diff --git a/setup/readme.md b/setup/readme.md
index 6b8ef15..fe5f8b2 100644
--- a/setup/readme.md
+++ b/setup/readme.md
@@ -1,6 +1,11 @@
Useful links
+md C:\mongodb\data
+md c:\data\db
+
Install windows service
+cd "C:\Program Files\MongoDB 2.6 Standard"
+
.\bin\mongod.exe --config "C:\mongodb\mongod.cfg" --install
Useful links
@@ -12,3 +17,9 @@ http://stackoverflow.com/questions/10108170/node-js-reuse-mongodb-reference
To setup db user see SetupDb.js
+For Azure VM setup endpoint on port 27017
+
+Open the firewall - http://itblog.gr/213/configuring-windows-firewall-from-the-command-line/
+
+netsh advfirewall firewall add rule name="MongoDb" protocol=TCP localport=27017 action=allow dir=IN
+
From baaa2d9dc0e81c5a253d935057cc1b58d27bc6a4 Mon Sep 17 00:00:00 2001
From: unknown
Date: Mon, 24 Nov 2014 01:09:18 -0800
Subject: [PATCH 5/6] Change form Sofia
---
public/index.html | 3 +++
1 file changed, 3 insertions(+)
diff --git a/public/index.html b/public/index.html
index 12ce071..90811c5 100644
--- a/public/index.html
+++ b/public/index.html
@@ -12,6 +12,7 @@
@@ -58,6 +59,8 @@
and MongoDB by
Christophe Coenraets.
The source code for this application is available in this repository on GitHub.
+
+ Hello from Sofia!!!
From 32e108163916f0f016d9f8a65f693f988e7f05aa Mon Sep 17 00:00:00 2001
From: unknown
Date: Thu, 22 Jan 2015 13:33:37 -0800
Subject: [PATCH 6/6] remove changes
---
public/index.html | 3 ---
1 file changed, 3 deletions(-)
diff --git a/public/index.html b/public/index.html
index 90811c5..12ce071 100644
--- a/public/index.html
+++ b/public/index.html
@@ -12,7 +12,6 @@
@@ -59,8 +58,6 @@
and MongoDB by
Christophe Coenraets.
The source code for this application is available in this repository on GitHub.
-
- Hello from Sofia!!!