-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
63 lines (52 loc) · 1.47 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
var sys = require('sys'),
fs = require('fs'),
http = require('http'),
url = require('url');
// server
var httpServer = http.createServer(function(req, res) {
res.writeHead(200, {'Content-Type':'text/html'});
res.write('hello');
var urlParts = url.parse(req.url);
if (urlParts.pathname === '/' + process.env.PPDELINQ_LOAD_KEY) {
loadData();
}
res.end();
});
httpServer.listen(process.env.PORT || 3000);
var nowjs = require('now'),
everyone = nowjs.initialize(httpServer, {
socketio: {
transports: ['xhr-polling', 'jsonp-polling'],
"polling duration": 10
}
}),
models = require('./models'),
Property = models.Property;
var loaded = 0;
// bulk load properties
function loadData() {
if (!loaded) {
var props1 = require('./props-load1.json');
var props2 = require('./props-load2.json');
var props3 = require('./props-load3.json');
Property.collection.insert(props1, {}, function(err){
console.log(err);
});
Property.collection.insert(props2, {}, function(err){
console.log(err);
});
Property.collection.insert(props3, {}, function(err){
console.log(err);
});
loaded = 1;
}
}
// now js search function
everyone.now.search = function(text, count, callback) {
// create regex for "contains" and ignore case
var regex = new RegExp(text.term, 'i');
// execute the search
Property.find({address: regex}, function(err, docs) {
callback(null, docs);
});
};