Skip to content

Commit

Permalink
add service.js and test.js
Browse files Browse the repository at this point in the history
  • Loading branch information
thongxuan committed Jun 1, 2015
1 parent d8c8572 commit 9cbee51
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
4 changes: 4 additions & 0 deletions conception/conception.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[16:44 01/06/2015]

URI:
localhost:1337/keeex?action=""&username=""&digest=""&path=""
1 change: 1 addition & 0 deletions test/html/service.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
THONG
52 changes: 52 additions & 0 deletions test/js/service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
var http = require('http');
var url = require('url');
var fs = require('fs');

var server = http.createServer(function(request, response) {

//parse url and respond base on action
var query = url.parse(request.url, true).query;
var action = query.action;
var path = query.path;

response.writeHead(200);
if (action=="keeexit")
{

if (!path && fs.existsSync(path))
{
response.writeHead(200);
/*TODO
return the path to the keeexed file or its content
*/
}
else
{
//return bad request
response.writeHead(400);
}
}
else if (action=="verify")
{
if (!path && fs.existsSync(path))
{
response.writeHead(200);
/*TODO
return whether the file is in the lastest version
*/
}
else
{
//return bad request
response.writeHead(400);
}
}
else
{
//action not supported
response.writeHead(404);
}
response.end();

}).listen(3000, '127.0.0.1');

37 changes: 37 additions & 0 deletions test/js/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
var http = require('http');


function getStatusCode(request, callback) {
var options = {
host: "127.0.0.1",
port: 3000,
path: request,
headers: {
Host: request
}
};
http.get(options, function(response) {
callback(response.statusCode);
});
}

function proceedReturnCode(code)
{
switch (code)
{
case 200:
//request success
break;
case 400:
//bad param
break;
case 404:
//action not found
break;
}
console.log(code);
}

var action = "keeexit";
var path = "E:\\test\\image.bmp";
getStatusCode("/keeex?action="+action+"&path="+path, proceedReturnCode);

0 comments on commit 9cbee51

Please sign in to comment.