Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
IcarusServer
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
icarus
IcarusServer
Commits
ba06ea2c
Commit
ba06ea2c
authored
Nov 27, 2015
by
andreagerino
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
cc6e8401
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
66 additions
and
1 deletion
+66
-1
storage.js
routes/storage.js
+66
-1
No files found.
routes/storage.js
View file @
ba06ea2c
var
express
=
require
(
'express'
);
var
express
=
require
(
'express'
);
var
router
=
express
.
Router
();
var
router
=
express
.
Router
();
var
debug
=
require
(
'debug'
)(
'Icarus:server'
);
router
.
get
(
'/'
,
function
(
req
,
res
,
next
)
{
var
mongoClient
=
require
(
'mongodb'
).
MongoClient
;
var
assert
=
assert
=
require
(
'assert'
);
// Connection URL
var
mongoUrl
=
'mongodb://icarus:icarus@webdev.ewlab.di.unimi.it:27017/icarus'
;
//Use connect method to test the connection to the Server
mongoClient
.
connect
(
mongoUrl
,
function
(
err
,
db
)
{
assert
.
equal
(
null
,
err
,
err
);
debug
(
"Connected to MongoDB database: "
+
db
.
databaseName
);
db
.
close
();
});
router
.
get
(
'/:resource_id'
,
function
(
req
,
res
,
next
)
{
res
.
sendStatus
(
200
);
res
.
sendStatus
(
200
);
});
});
router
.
post
(
'/'
,
function
(
req
,
res
,
next
){
mongoClient
.
connect
(
mongoUrl
,
function
(
err
,
db
)
{
if
(
err
!=
null
){
debug
(
err
);
next
(
err
);
}
else
{
var
collection
=
db
.
collection
(
'resources'
);
var
resource
=
req
.
body
;
if
(
Object
.
keys
(
resource
)
>
0
)
{
collection
.
insertOne
(
resource
,
function
(
err
,
r
)
{
if
(
err
!=
null
)
{
debug
(
err
);
next
(
err
);
}
else
{
db
.
close
();
res
.
sendStatus
(
201
);
}
});
}
else
{
var
error
=
new
Error
(
"You can't store an empty resource!"
);
error
.
status
=
400
;
debug
(
err
);
next
(
error
);
}
}
});
});
module
.
exports
=
router
;
module
.
exports
=
router
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment