-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.c.js
91 lines (74 loc) · 2.04 KB
/
app.c.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var http = require("http"),
Rx = require("rx"),
mongo = require("mongodb").MongoClient;
var Server = (function (_http$Server) {
function Server() {
http.Server.call(this);
}
_inherits(Server, _http$Server);
_prototypeProperties(Server, null, {
requests: {
value: function requests() {
return Rx.Node.fromEvent(this, "request", function (args) {
return { req: args[0], res: args[1] };
});
},
writable: true,
enumerable: true,
configurable: true
}
});
return Server;
})(http.Server);
var url = "mongodb://localhost:27017/myproject";
var server = new Server();
var connect = function () {
return rx.Observable.create(function (o) {
return mongo.connect(url);
}, function (err, db) {
if (err) {
return o.onError(err);
}
return o.onNext(db);
}).publish().refCount();
};
var addItem = function (db) {
return rx.Observable.create(function (o) {
return db.collection.items.find().toArray(function (err, d) {
if (err) {
o.onError(err);
} else {
o.onNext(d);
o.onCompleted();
}
return function () {
return db.close();
};
});
});
};
console.log("loading");
var server = new Server();
server.requests().subscribe(function (s) {
return s.res.end("teste");
});
server.listen(1000);