Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'release/v0.14.0'

  • Loading branch information...
commit 1ed91240e319579e9ff56e31e76ca031e4990d7b 2 parents e1f2fba + 42ae66d
@andzdroid authored
View
2  .gitignore
@@ -15,3 +15,5 @@ results
node_modules
npm-debug.log
+
+config.js
View
15 README.md
@@ -17,7 +17,6 @@ Current features:
Planned features:
-* Error messages/responses
* Support for replica set connections
* Web-based command-line interface
* Site authentication
@@ -45,7 +44,7 @@ These screenshots are from version 0.11.0.
Usage
-----
-To install:
+**To install:**
npm install mongo-express
@@ -53,17 +52,19 @@ Or if you want to install a global copy:
npm install -g mongo-express
-To configure:
+**To configure:**
-Open config.js and fill in your MongoDB server connection and admin auth details.
+Copy `config.default.js` into a new file called `config.js`.
-To run:
+Fill in your MongoDB connection details, and any other options you want to change.
+
+**To run:**
node app
-To use:
+**To use:**
-Visit http://localhost:8081 or whatever URL/port you entered into your config.
+Visit `http://localhost:8081` or whatever URL/port you entered into your config.
License
View
16 app.js
@@ -16,6 +16,8 @@ var swig = require('swig');
var swigFilters = require('./filters');
var app = express();
+var config = require('./config');
+
//Set up swig
swig.init({
root: __dirname + '/views',
@@ -48,6 +50,8 @@ app.configure(function(){
app.use(express.logger('dev'));
app.use(express.static(__dirname + '/public'));
app.use(express.bodyParser());
+ app.use(express.cookieParser(config.site.cookieSecret));
+ app.use(express.session({ secret: config.site.sessionSecret }));
app.use(express.methodOverride());
app.use(app.router);
});
@@ -58,7 +62,6 @@ app.configure('development', function(){
//Set up database stuff
-var config = require('./config');
var host = config.mongodb.server || 'localhost';
var port = config.mongodb.port || mongodb.Connection.DEFAULT_PORT;
var dbOptions = {
@@ -204,6 +207,17 @@ app.locals.use(function(req, res) {
res.locals.baseHref = config.site.baseUrl;
res.locals.databases = databases;
res.locals.collections = collections;
+
+ //Flash messages
+ if (req.session.success) {
+ res.locals.messageSuccess = req.session.success;
+ delete req.session.success;
+ }
+
+ if (req.session.error) {
+ res.locals.messageError = req.session.error;
+ delete req.session.error;
+ }
});
View
4 config.js → config.default.js
@@ -43,7 +43,9 @@ module.exports = {
//baseUrl: the URL that mongo express will be located at
//Remember to add the forward slash at the end!
baseUrl: 'http://localhost:8081/',
- port: 8081
+ port: 8081,
+ cookieSecret: 'cookiesecret',
+ sessionSecret: 'sessionsecret'
},
options: {
//documentsPerPage: how many documents you want to see at once in collection view
View
2  package.json
@@ -2,7 +2,7 @@
"author": "Chun-hao Hu <hu.chunhao@gmail.com> (http://blog.huchunhao.com)",
"name": "mongo-express",
"description": "Web-based admin interface for MongoDB",
- "version": "0.13.0",
+ "version": "0.14.0",
"repository": {
"type": "git",
"url": "git://github.com/andzdroid/mongo-express.git"
View
35 routes/collection.js
@@ -61,25 +61,26 @@ exports.viewCollection = function(req, res, next) {
exports.addCollection = function(req, res, next) {
var name = req.body.collection;
- if (name === undefined) {
- //TODO: handle error
+ if (name === undefined || name.length == 0) {
+ req.session.error = "You forgot to enter a collection name!";
return res.redirect('back');
}
//Collection names must begin with a letter or underscore, and can contain only letters, underscores, numbers or dots
if (!name.match(/^[a-zA-Z_][a-zA-Z0-9\._]*$/)) {
- //TODO: handle error
+ req.session.error = "That collection name is invalid.";
return res.redirect('back');
}
req.db.createCollection(name, function(err, collection) {
if (err) {
- //TODO: handle error
+ req.session.error = "Something went wrong: " + err;
console.error(err);
+ return res.redirect('back');
}
req.updateCollections(req.db, req.dbName, function() {
- //TODO: use session flash to show success or error message
+ req.session.success = 'Collection created!';
res.redirect('/db/' + req.dbName + '/' + name);
});
});
@@ -89,18 +90,21 @@ exports.addCollection = function(req, res, next) {
exports.deleteCollection = function(req, res, next) {
req.collection.drop(function(err, result) {
if (err) {
- //TODO: handle error
+ req.session.error = "Something went wrong: " + err;
console.error(err);
+ return res.redirect('back');
}
//If delete was successful, result === true
req.updateCollections(req.db, req.dbName, function(err) {
if (err) {
- //TODO: handle error
+ req.session.error = "Something went wrong: " + err;
console.error(err);
+ return res.redirect('back');
}
+ req.session.success = "Collection '" + req.collectionName + "' deleted!";
res.redirect('/db/' + req.dbName);
});
});
@@ -110,24 +114,31 @@ exports.deleteCollection = function(req, res, next) {
exports.renameCollection = function(req, res, next) {
var name = req.body.collection;
- if (name == undefined) {
- //TODO: handle error
+ if (name == undefined || name.length == 0) {
+ req.session.error = "You forgot to enter a collection name!";
return res.redirect('back');
}
//Collection names must begin with a letter or underscore, and can contain only letters, underscores, numbers or dots
if (!name.match(/^[a-zA-Z_][a-zA-Z0-9\._]*$/)) {
- //TODO: handle error
+ req.session.error = "That collection name is invalid.";
return res.redirect('back');
}
req.collection.rename(name, function(err, collection) {
if (err) {
- //TODO: handle error
+ req.session.error('Something went wrong: ' + err);
console.error(err);
+ return res.redirect('back');
}
- req.updateCollections(req.db, req.dbName, function() {
+ req.updateCollections(req.db, req.dbName, function(err) {
+ if (err) {
+ req.session.error('Something went wrong: ' + err);
+ return res.redirect('back');
+ }
+
+ req.session.success('Collection renamed!');
res.redirect('/db/' + req.dbName + '/' + name);
});
});
View
26 routes/document.js
@@ -14,8 +14,8 @@ exports.viewDocument = function(req, res, next) {
exports.addDocument = function(req, res, next) {
var doc = req.body.document;
- if (doc == undefined) {
- //TODO: handle error
+ if (doc == undefined || doc.length == 0) {
+ req.session.error = "You forgot to enter a document!";
return res.redirect('back');
}
@@ -23,18 +23,19 @@ exports.addDocument = function(req, res, next) {
try {
docJSON = JSON.parse(doc);
} catch (err) {
- //TODO: handle error
+ req.session.error = "That document is not valid!";
console.error(err)
return res.redirect('back');
}
req.collection.insert(docJSON, {safe: true}, function(err, result) {
if (err) {
- //TODO: handle error
+ req.session.error = "Something went wrong: " + err;
console.error(err);
return res.redirect('back');
}
+ req.session.success = "Document added!";
res.redirect('/db/' + req.dbName + '/' + req.collectionName);
});
};
@@ -43,8 +44,8 @@ exports.addDocument = function(req, res, next) {
exports.updateDocument = function(req, res, next) {
var doc = req.body.document;
- if (doc == undefined) {
- //TODO: handle error
+ if (doc == undefined || doc.length == 0) {
+ req.session.error = "You forgot to enter a document!";
return res.redirect('back');
}
@@ -52,7 +53,7 @@ exports.updateDocument = function(req, res, next) {
try {
docJSON = JSON.parse(doc);
} catch (err) {
- //TODO: handle error
+ req.session.error = "That document is not valid!";
console.error(err);
return res.redirect('back');
}
@@ -61,13 +62,14 @@ exports.updateDocument = function(req, res, next) {
req.collection.update(req.document, docJSON, {safe: true}, function(err, result) {
if (err) {
- //TODO: handle error
//document was not saved
+ req.session.error = "Something went wrong: " + err;
console.error(err);
return res.redirect('back');
}
- return res.redirect('/db/' + req.dbName + '/' + req.collectionName);
+ req.session.success = "Document updated!";
+ res.redirect('/db/' + req.dbName + '/' + req.collectionName);
});
};
@@ -75,10 +77,12 @@ exports.updateDocument = function(req, res, next) {
exports.deleteDocument = function(req, res, next) {
req.collection.remove(req.document, {safe: true}, function(err, result) {
if (err) {
- //TODO: handle error
+ req.session.error = "Something went wrong! " + err;
console.error(err);
+ return res.redirect('back');
}
- return res.redirect('/db/' + req.dbName + '/' + req.collectionName);
+ req.session.success = "Document deleted!";
+ res.redirect('/db/' + req.dbName + '/' + req.collectionName);
});
};
View
6 views/database.html
@@ -18,7 +18,7 @@
<form class="well form-inline" method="POST">
<div class="input-prepend">
<span class="add-on">{{ dbName }} . </span>
- <input class="input-medium" type="text" id="collection" name="collection" placeholder="Collection Name">
+ <input class="input-medium" type="text" id="collection" name="collection" placeholder="Collection Name" title="Collection Name">
</div>
<button type="submit" class="btn btn-primary">
<i class="icon-folder-open icon-white"></i>
@@ -26,6 +26,10 @@
</button>
</form>
+<script>
+ $('#collection').popover({content: "Collection names must begin with a letter or underscore, and can contain only letters, numbers, underscores and dots."});
+</script>
+
<h2>Collections</h2>
<table class="table table-bordered table-striped table-condensed">
View
14 views/layout.html
@@ -84,6 +84,20 @@
<h1 id="pageTitle">{{ title }}</h1>
</div>
+ {% if messageSuccess %}
+ <div class="alert alert-success">
+ <button class="close" data-dismiss="alert">×</button>
+ <strong>{{ messageSuccess }}</strong>
+ </div>
+ {% endif %}
+
+ {% if messageError %}
+ <div class="alert alert-error">
+ <button class="close" data-dismiss="alert">×</button>
+ <strong>{{ messageError }}</strong>
+ </div>
+ {% endif %}
+
{% block content %}{% endblock %}
</div>
</div>
Please sign in to comment.
Something went wrong with that request. Please try again.