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,123 +6,129 @@ 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){
assert.equal(null, err, err);
debug("Connected to MongoDB database: "+db.databaseName);
var icarusDb;
var router = express.Router();
icarusDb = db;
mongoClient.connect(mongoUrl , function(err, db) {
});
assert.equal(null, err, err);
debug("Connected to MongoDB database: "+db.databaseName);
router.get('/:resource_id', function(req, res, next) {
icarusDb = db;
var collection = icarusDb.collection('resources');
});
var _id = new ObjectID(req.params.resource_id);
collection.find({"_id":_id}).limit(1).next(function(err, doc){
router.get('/:resource_id', function(req, res, next) {
if(err!=null){
var collection = icarusDb.collection('resources');
debug(err);
next(err);
var _id = new ObjectID(req.params.resource_id);
collection.find({"_id":_id}).limit(1).next(function(err, doc){
}else{
if(err!=null){
if(doc==undefined){
debug(err);
next(err);
res.sendStatus(404);
}else{
}else{
if(doc==undefined){
res.send(doc);
res.sendStatus(404);
}
}else{
}
res.send(doc);
});
}
});
}
router.post('/', function(req, res, next){
});
var collection = icarusDb.collection('resources');
var resource = req.body;
});
if(Object.keys(resource).length>0) {
router.post('/', function(req, res, next){
var timestampContainer = getTimestampContainer(resource);
var collection = icarusDb.collection('resources');
var resource = req.body;
if(timestampContainer!=undefined){
if(Object.keys(resource).length>0) {
preprocessTimestampContainer(timestampContainer);
var timestampContainer = getTimestampContainer(resource);
}
if(timestampContainer!=undefined){
collection.insertOne(resource, function (err, r) {
preprocessTimestampContainer(timestampContainer);
if (err != null) {
}
debug(err);
next(err);
collection.insertOne(resource, function (err, r) {
} else {
if (err != null) {
res.statusCode = 201;
res.send({"_id":r.insertedId});
debug(err);
next(err);
}
} else {
});
res.statusCode = 201;
res.send({"_id":r.insertedId});
}else{
}
var error = new Error("You can't store an empty resource!");
error.status = 400;
});
debug(error);
next(error);
}else{
}
var error = new Error("You can't store an empty resource!");
error.status = 400;
});
debug(error);
next(error);
function getTimestampContainer(arg){
}
if(arg['timestamp']!=undefined&&(arg['timestamp']['utc']!=undefined||arg['timestamp']['user']!=undefined))
return arg['timestamp'];
});
return {};
function getTimestampContainer(arg){
}
if(arg['timestamp']!=undefined&&(arg['timestamp']['utc']!=undefined||arg['timestamp']['user']!=undefined))
return arg['timestamp'];
function preprocessTimestampContainer(container){
return {};
var utcSeconds = container['utc'];
var userSeconds = container['user'];
}
if(utcSeconds!=undefined){
function preprocessTimestampContainer(container){
var utcMsec = utcSeconds * 1000;
container['utc'] = new Date(utcMsec);
var utcSeconds = container['utc'];
var userSeconds = container['user'];
}
if(utcSeconds!=undefined){
var utcMsec = utcSeconds * 1000;
container['utc'] = new Date(utcMsec);
if(userSeconds!=undefined){
}
var userMsec = userSeconds * 1000;
container['user'] = new Date(userMsec);
if(userSeconds!=undefined){
}
var userMsec = userSeconds * 1000;
container['user'] = new Date(userMsec);
container['server'] = new Date();
}
}
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