Skip to content

Commit

Permalink
abstracted into a package, added index.js which uses require assassin…
Browse files Browse the repository at this point in the history
….js,

fixed for in loops bug
  • Loading branch information
Adithya C committed Mar 7, 2013
1 parent 60f87eb commit e1f603a
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 1,703 deletions.
31 changes: 17 additions & 14 deletions assassin.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/* index.js
/* assassin.js
***** Part of AssassinJS *****
- (c)2013 Adithya and Sai Teja under MIT (Open Source) License
This is the file that needs to be run by node.
It initializes the server to listen on Specified Port Number and Address.
This is the file that initializes the server to listen on Specified Port Number and Address.
The settings are taken from the configuration file.
All the actions are logged using the logger.
Expand All @@ -16,17 +15,21 @@ system['config'] = require('./system/config');
system['logger'] = require('./system/logger');
system['router'] = require('./system/router');

var server = http.createServer();

var config = system.config.getConfig();
system.logger.write('config object='+JSON.stringify(config));
server.on('request',system.router.route);

if(config.port!=undefined && config.address!=undefined)
function assassinate()
{
server.listen(config.port,config.address);
system.logger.write('Server running at '+config.address+':'+config.port);
var server = http.createServer();
var config = system.config.getConfig();
//system.logger.write('config object='+JSON.stringify(config));
server.on('request',system.router.route);

if(config.port!=undefined && config.address!=undefined)
{
server.listen(config.port,config.address);
system.logger.write('Server running at '+config.address+':'+config.port);
}
else
system.logger.write('Config Parameters not defined: port and address');
}
else
system.logger.write('Config Parameters not defined: port and address');

exports.assassinate = assassinate;

6 changes: 1 addition & 5 deletions fileserver/contenttypelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,10 @@ fs.readFile('./fileserver/filetypelist.txt',function(err,data2){

for(row in listentries)
{
row = listentries[row];
filetypemap[row.split('\t')[0].split('.')[1]] = row.split('\t')[1];
}

/*
$.each(listentries,function(key,value){
filetypemap[value.split('\t')[0].split('.')[1]] = value.split('\t')[1];
});
*/
}
});

Expand Down
12 changes: 12 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* index.js
***** Part of AssassinJS *****
- (c)2013 Adithya and Sai Teja under MIT (Open Source) License
This is the file that needs to be run by node.
*/

var assassin = require('./assassin');

//This function invokes assassin
assassin.assassinate();
12 changes: 6 additions & 6 deletions system/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ else
var listentries = data.toString().split('\n');

for(row in listentries)
{
var valuepair = row.split('\t');
{
var valuepair = listentries[row].split('\t');
//logger.write(listentries[row]+','+valuepair);
config[valuepair[0]] = valuepair[1];
}

Expand All @@ -41,22 +42,21 @@ else

for(row in listentries)
{
var values = row.split('\t');
var values = listentries[row].split('\t');
var routeObj={};
routeObj.path=values[1];
routeObj.method=values[0];
routeObj.target=values[2];
if(routes[routeObj.path]===undefined && routeObj.path!=undefined) routes[routeObj.path]={};
if(routes[routeObj.path]!=undefined)routes[routeObj.path][routeObj.method] = routeObj.target;
logger.write('routeObj = '+JSON.stringify(routeObj)+' and routes= '+JSON.stringify(routes));
//logger.write('routeObj = '+JSON.stringify(routeObj)+' and routes= '+JSON.stringify(routes));
}

}


function getConfig()
{
logger.write('returning config');
logger.write('returning config = '+JSON.stringify(config));
return config;
}

Expand Down
Loading

0 comments on commit e1f603a

Please sign in to comment.