Skip to content

Commit 5d3c020

Browse files
committed
first release \o/
1 parent 9883842 commit 5d3c020

File tree

4 files changed

+82
-0
lines changed

4 files changed

+82
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

app.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
var express = require('express');
2+
var redis = require('redis');
3+
var async = require('async');
4+
5+
var app = express();
6+
app.use(express.bodyParser());
7+
8+
var redisClient = redis.createClient();
9+
10+
var logger = function(req, res, next) {console.log(req.body); next();};
11+
12+
var auth = express.basicAuth(function(user, pass) {
13+
return pass == process.env.PASSWORD;
14+
});
15+
16+
app.use(logger);
17+
app.use(auth);
18+
19+
app.get('/', function(req, res) {
20+
redisClient.lrange('ragots', 0, -1, function(err, ragotIds) {
21+
async.parallel(ragotIds.map(function(id) {
22+
return function(cb) { redisClient.get('ragots:'+id, cb); };
23+
}), function(err, ragots) {
24+
res.render('index.jade', { ragots: ragots });
25+
});
26+
});
27+
});
28+
29+
app.post('/ragots', function(req, res) {
30+
redisClient.incr('ragots:count', function(err, i) {
31+
async.parallel([
32+
function(cb) { redisClient.set('ragots:'+i, req.body.message, cb); },
33+
function(cb) { redisClient.lpush('ragots', i, cb); }
34+
], function(err) {
35+
if(!err) res.redirect('/');
36+
});
37+
});
38+
});
39+
40+
app.listen(3000);

package.json

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "ragots",
3+
"version": "0.0.0",
4+
"description": "- Paul Chobert",
5+
"main": "app.js",
6+
"dependencies": {
7+
"express": "~3.1.0",
8+
"async": "~0.2.6",
9+
"jade": "~0.28.2",
10+
"redis": "~0.8.2",
11+
"underscore": "~1.4.4",
12+
"supervisor": "~0.5.2"
13+
},
14+
"devDependencies": {},
15+
"scripts": {
16+
"test": "echo \"Error: no test specified\" && exit 1"
17+
},
18+
"repository": {
19+
"type": "git",
20+
"url": "git://github.com/barodeur/ragots.git"
21+
},
22+
"engines": {
23+
"node": "0.8.x",
24+
"npm": "1.1.x"
25+
},
26+
"author": "",
27+
"license": "BSD",
28+
"readmeFilename": "README.md",
29+
"gitHead": "19d0eef57c6657ae658fcabfb020db5c3c6de1d8"
30+
}

views/index.jade

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
doctype 5
2+
html(lang="fr")
3+
head
4+
title Ragots
5+
body
6+
form(action="/ragots", method="POST")
7+
input(type="text", name="message", autofocus)
8+
input(type="submit")
9+
ul#ragots
10+
each ragot in ragots
11+
li.ragot= ragot

0 commit comments

Comments
 (0)