-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ddbc1ce
Showing
6 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
dump.rdb | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "d2", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"redis": "^2.1.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
|
||
</head> | ||
|
||
<body> | ||
<h5>My Mailing List</h5> | ||
<form action="/" method="POST"> | ||
<p>name</p> | ||
<input type="text" placeholder="name" name="name"></input> | ||
<br> | ||
<p>surname</p> | ||
<input type="text" placeholder="surname" name="surname"></input> | ||
<br> | ||
<p>email</p> | ||
<input type="text" placeholder="email" name="email"></input> | ||
<br> | ||
<input type="submit" ></input> | ||
</form> | ||
<ul class="details"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
</ul> | ||
|
||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
|
||
// function sortingShitOut(){ | ||
function requestingOutputFromDatabase(){ | ||
var res = new XMLHttpRequest(); | ||
res.open('GET', '/'); | ||
res.send(); | ||
return res.responseText; | ||
|
||
// out.onreadystatechange = function(){ | ||
// if(out.readyState === 4 && out.status === 200){ | ||
|
||
// document.getElementById('favTing').innerHTML = out. | ||
// } | ||
}; | ||
|
||
} | ||
// | ||
// function gettingInputFromDatabase(){ | ||
// var out = new XMLHttpRequest(); | ||
// out.onreadystatechange(function(){ | ||
// if (out.readyState === 4 && out.status === 200){ | ||
// console.log(out.responseText); | ||
// document.getElementsByClassName('favourite-things').innerHTML = out.responseText; | ||
// } | ||
// }); | ||
// out.open('GET', '/'); | ||
// out.send(); | ||
// } | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
var http = require('http'); | ||
var fs = require('fs'); | ||
var port = 8000; | ||
console.log("Server running at http://localhost:" + port); | ||
var index1 = fs.readFileSync(__dirname + '/public/index1.html'); | ||
var index2 = fs.readFileSync(__dirname + '/public/index2.html'); | ||
var server = http.createServer(handler); | ||
server.listen(port); | ||
var redis = require("redis"); | ||
var client = redis.createClient(); | ||
var item=""; | ||
|
||
function handler(req,res){ | ||
if (req.method === 'POST') { | ||
var body = ''; | ||
req.on('data', function (dataChunk) { | ||
body += dataChunk; | ||
}); | ||
req.on('end', function () { | ||
var entries = body.split('&'); | ||
var deets = entries.map(splitByEquals); | ||
client.incr('userCount', function(err, userCount){ | ||
var id = userCount; | ||
client.HSET('user:' + id, "name", deets[0][1], redis.print); | ||
client.HSET('user:' + id, "surname", deets[1][1], redis.print); | ||
client.HSET('user:' + id, "email", deets[2][1],redis.print); | ||
}); | ||
}); | ||
} else if (req.method === 'GET') { | ||
res.writeHead(200, {"Content-Type": "text/html"}); | ||
client.get('userCount', function(err, reply){ | ||
res.write(index1); | ||
var userCount = reply; | ||
for (var i = 1; i <= userCount; i++){ | ||
var count = 1; | ||
count ++; | ||
client.HGETALL('user:'+i, function (err,reply){ | ||
res.write('<li>' + reply.name + ', ' + reply.surname + ', ' + reply.email.replace(/%40/, '@') + '</li>'); | ||
if (count === userCount) { | ||
res.end(index2); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
function splitByEquals(arg){ | ||
return arg.split("="); | ||
} |