forked from shimondoodkin/nodejs-mongodb-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
executable file
·88 lines (73 loc) · 2.24 KB
/
test.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
require.paths.unshift(__dirname); //make local paths accecible
var sys = require("sys");
var http = require('http'); // allaws to create http server
var mongo = require('deps/node-mongodb-native/lib/mongodb');
var _ = require("deps/nodejs-clone-extend/merger");
var smsquee=[]; // new Array();
function sendsms(users,message,callback)
{
var smsobject={}; // create new empty object
smsobject.users=users;
smsobject.message=message;
callback('Thanks for testing');
}
function testsms()
{
for(var i=0;i<smsquee.length;i++)
{
}
}
function handlerequest(request, response)
{
switch (url.parse(request.url).pathname)
{
case '/':
//show form
response.writeHead(200, {'Content-Type': 'text/html'});
response.write
(
'<form action="/test" method="GET">' +
'<input type="submit" name="submit" value="Test">' +
'<input type="hidden" name="rand" value="'+Math.random()+'">' +
'</form>'
);
response.end();
break;
case '/test':
var phonenumbers=[];
phonenumbers.push({name:'shimon',phone:'972547490305'});
//phonenumbers.push({name:'alex',phone:'972545557456'});
var message={
text: (new Date).toString()+ 'áãé÷ú SMS' ,
link: 'http://google.com/'
};
sendsms(phonenumbers, message, function (ret_value){
response.writeHead(200, {'Content-Type': 'text/plain'});
response.write(
ret_value +
'<form action="/test" method="GET">' +
'<input type="submit" value="Test Again">' +
'<input type="hidden" name="rand" value="'+Math.random()+'">' +
'</form>'
);
response.end();
});
break;
default:
//show 404
response.writeHead(404, {'Content-Type': 'text/plain'});
response.write('404 - Please try again.');
response.end();
break;
}
}
var db = new mongo.Db('webappdb', new mongo.Server('127.0.0.1', mongo.Connection.DEFAULT_PORT , {}), {});
var httpserver;
db.open(function(err, db)
{
httpserver=http.createServer(handlerequest);
httpserver.listen(8124);
setTimeout(testsms,3000);
});
var autoexit_watch=require('deps/nodejs-autorestart/autoexit').watch;
autoexit_watch(__dirname,".js");