Skip to content

Commit

Permalink
Initial Loadup of my node exercises
Browse files Browse the repository at this point in the history
  • Loading branch information
Gunnar Magholder committed Jul 11, 2013
0 parents commit 4e706b3
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
*~
.*
Binary file added .silkveil.js.swp
Binary file not shown.
19 changes: 19 additions & 0 deletions chat.js
@@ -0,0 +1,19 @@
var net = require('net');
var sockets = [];

net.createServer(function (socket) {
sockets.push(socket);
socket.write('Hallo!\n');
socket.on('data', function(data) {
for(var i = 0; i< sockets.length; i++) {
if(sockets[i] == socket) {
continue;
};
sockets[i].write(data);
}
});
socket.on('end', function() {
var i = sockets.indexOf(socket);
sockets.splice(i,1);
});
}).listen(3000);
12 changes: 12 additions & 0 deletions http_server.js
@@ -0,0 +1,12 @@
var http = require('http');

var server = http.createServer(function(req,res) {
console.log('Initializing Server...');
res.writeHead(200, {
'content-type': 'text/plain'
});
res.write('Hallo ');
setTimeout(function(){
res.end('Welt!');
},2000);
}).listen(3000);
4 changes: 4 additions & 0 deletions hw.js
@@ -0,0 +1,4 @@
setTimeout(function() {
console.log('Welt!');
}, 2000);
console.log("Hallo ");
24 changes: 24 additions & 0 deletions silkveil.js
@@ -0,0 +1,24 @@
var http = require('http');
var mappings = {
'magholder': {
action: 'redirect',
url: 'http://magholder.info',
type: 'permanent'
},
'ursel': {
action: 'download',
url: 'https://www.facebook.com/photo.php?fbid=10201281285979248&l=76a440aac7',
fileName: 'ursel.jpg',
forceDownload: false
}
};
http.createServer(function(req,res) {
var alias = req.url.substring(1);
var mapping = mappings[alias] || {
action: 'error',
statusCode: 404,
data: 'file not found'
};
actions[mapping.action](res.mapping);
console.log(mapping);
}).listen(3000);

0 comments on commit 4e706b3

Please sign in to comment.