var restify = require('restify');
var mongojs = require('mongojs');

var db = mongojs.connect('localhost:27017/backpack', ['alerts']);
// var alerts = db.collection('alerts');

var server = restify.createServer({
		name: 'backpacklistener',
});

server.listen(3001);

server.post('/netdata', function create(req, res, next) {

		var body = '';
    req.on('data', function (data) {
        body += data;
    });
    req.on('end', function () {
				// simple search for bad domain connect.facebook.net
				// nslookup: 23.73.127.228
				var stringbody = body.toString();
				var facedetect = stringbody.indexOf("facebook");
				if (facedetect != -1) { // we found facebook
						// find where it came from
						var regpattern = /www\.(.*)\.com/;
						var result = stringbody.match(regpattern);
						// store alert's result domain
						console.log(result[0]);
						db.alerts.save({msg: result[0]});
				}
				
				// TODO DB storage and non-crazy searching
				// db.netdata.save(product,
  			// 								function (err, data) {
  			// 										res.writeHead(200, {
  			// 												'Content-Type': 'application/json; charset=utf-8'
  			// 										});
  			// 										res.end(JSON.stringify(data));
  			// 								});
    });
		res.end('AAAAAAAAAAAAA');
});

@@ -724,24 +724,74 @@
 n = 
-/www%5C.(.*)%5C.com/
+new RegExp(%22%5Bhtps:%5D*//(%5Ba-zA-Z0-9%5C%5C-%5C%5C.%5D*%5C%5C.%5Ba-zA-Z%5D%7B2,3%7D)%22, %22gi%22)
 ;%0A%09%09
@@ -874,22 +874,56 @@
  domain%0A
-%09%09%09%09%09%09
+            if (result) %7B%0A              
 console.
@@ -938,22 +938,30 @@
 lt%5B0%5D);%0A
-%09%09%09%09%09%09
+              
 db.alert
@@ -972,36 +972,120 @@
 ve(%7B
-msg: result%5B0%5D%7D);
+%0A                msg: result%5B0%5D,%0A                created_date: Date.now()%0A              %7D);%0A            %7D
 %0A%09%09%09%09%7D%0A
-%09%09%09%09
 %0A%09%09%09

Update regex and save only if result not null