Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This is AJ #18

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
"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.8.4",
"npm": "1.1.49"
"node": "0.10.32",
"npm": "1.4.9"
}
}
33 changes: 7 additions & 26 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,10 @@ 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. 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
44 changes: 42 additions & 2 deletions routes/wines.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,49 @@
var mongo = require('mongodb');


var Server = mongo.Server,
Db = mongo.Db,
BSON = mongo.BSONPure;

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);

var server = new Server('localhost', 27017, {auto_reconnect: true});
db = new Db('winedb', server, {safe: true});
// callback: (err, db)
function openDatabase(callback) {
db.open(function(err, db) {
if (err)
return callback(err);

console.log('Database connected');

return callback(null, db);
});
}

// 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) {
Expand All @@ -16,6 +54,8 @@ db.open(function(err, db) {
populateDB();
}
});
} else {
console.log("Error while connecting to database " + JSON.stringify(err));
}
});

Expand Down
14 changes: 14 additions & 0 deletions setup/SetupDB.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

Run .\bin\mongo --port 27017


use wine
db.createUser(
{
user: "wineUser",
pwd: "1XXXXXXX",
roles: [
{ role: "readWrite", db: "wine" },
]
}
)
9 changes: 9 additions & 0 deletions setup/mongod.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
systemLog:
destination: file
path: "/mongodb/mongodb.log"
logAppend: true
storage:
journal:
enabled: true
net:
port: 27017
25 changes: 25 additions & 0 deletions setup/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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
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

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