forked from alexpaley/Buckets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
48 lines (33 loc) · 1.19 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
var mongo = require('mongodb');
var Server = mongo.Server,
DB = mongo.Db,
BSON = mongo.BSONPure;
url = require('url');
urlItems = url.parse(process.env.MONGO_DB);
var server = new Server(urlItems.hostname, urlItems.port, {auto_reconnect: true});
db_init = new DB('bucketdb', server);
user = urlItems.auth.split(':');
db_init.open(function(err, db) {
db_init.authenticate(user[0], user[1], function(err, res) {
var express = require('express'),
buckets = require('./routes/buckets')(db);
uploads = require('./routes/fileUploads')(db);
// mailman = require('./routes/emailer')(db);
var app = express();
var __root = function() {
return require('path').normalize(__dirname);
};
app.configure(function() {
app.use(express.logger('dev'));
app.use(express.bodyParser());
});
app.use(express.static( __root() +'/public'));
app.get("/api", buckets.findAll);
app.post("/api", buckets.addBucket);
app.put("/api/:id", buckets.updateBucket);
app.delete("/api/:id", buckets.deleteBucket);
app.post("/target", uploads.addFile);
app.listen(3000);
console.log('Listening on port 3000...');
});
});