Commit 7b32498d authored by andreagerino's avatar andreagerino

Editing Storage endpoint class to specify the mongodb connection URL as a...

Editing Storage endpoint class to specify the mongodb connection URL as a parameter. Public storage endpoint added.
parent c73328ae
......@@ -3,7 +3,9 @@ var path = require('path');
var logger = require('morgan');
var bodyParser = require('body-parser');
var storage = require('./routes/storage');
var storage = require('./routes/storage')('mongodb://icarus:icarus@localhost:27017/icarus');
var public_storage = require('./routes/storage')('mongodb://public:public@localhost:27017/public');
var services = require('./routes/services');
var app = express();
......@@ -31,6 +33,7 @@ app.use(function(req, res, next) {
});
app.use('/icarus/str', storage);
app.use('/icarus/public', public_storage);
app.use('/icarus/svc', services);
// catch 404 and forward to error handler
......
var express = require('express');
var router = express.Router();
var debug = require('debug')('Icarus:server');
var mongoClient = require('mongodb').MongoClient;
......@@ -7,21 +6,23 @@ var ObjectID = require('mongodb').ObjectID;
var assert = assert = require('assert');
// Connection URL
var mongoUrl = 'mongodb://icarus:icarus@localhost:27017/icarus';
module.exports = (
//Connect to the server and intialise the pool
var icarusDb;
mongoClient.connect(mongoUrl, function(err, db) {
function(mongoUrl){
var icarusDb;
var router = express.Router();
mongoClient.connect(mongoUrl , function(err, db) {
assert.equal(null, err, err);
debug("Connected to MongoDB database: "+db.databaseName);
icarusDb = db;
});
});
router.get('/:resource_id', function(req, res, next) {
router.get('/:resource_id', function(req, res, next) {
var collection = icarusDb.collection('resources');
......@@ -49,9 +50,9 @@ router.get('/:resource_id', function(req, res, next) {
});
});
});
router.post('/', function(req, res, next){
router.post('/', function(req, res, next){
var collection = icarusDb.collection('resources');
var resource = req.body;
......@@ -92,18 +93,18 @@ router.post('/', function(req, res, next){
}
});
});
function getTimestampContainer(arg){
function getTimestampContainer(arg){
if(arg['timestamp']!=undefined&&(arg['timestamp']['utc']!=undefined||arg['timestamp']['user']!=undefined))
return arg['timestamp'];
return {};
}
}
function preprocessTimestampContainer(container){
function preprocessTimestampContainer(container){
var utcSeconds = container['utc'];
var userSeconds = container['user'];
......@@ -124,6 +125,10 @@ function preprocessTimestampContainer(container){
container['server'] = new Date();
}
}
return router;
}
module.exports = router;
);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment