-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.js
58 lines (58 loc) · 1.65 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
(function() {
var Express, Log, Robohash, Robostore, app, log, robostore;
Log = require('log');
log = new Log(Log.DEBUG);
Express = require('express');
app = Express.createServer();
Robohash = require('./lib/robohash');
Robostore = require('./lib/robostore');
robostore = Robostore.getStorage("" + __dirname + "/data/robostore");
app.configure(function() {
app.set('views', "" + __dirname + "/views");
app.set('view engine', 'jade');
app.use(Express.bodyParser());
return app.use(Express.methodOverride());
});
app.configure('development', function() {
return app.use(Express.errorHandler({
dumpExceptions: true,
showStack: true
}));
});
app.configure('production', function() {
return app.use(Express.errorHandler());
});
app.configure(function() {
app.use(app.router);
return app.use(Express.static("" + __dirname + "/public"));
});
app.get('/', function(req, res) {
return res.render('index', {
size: 100,
rows: 8,
cols: 8
});
});
app.get('/:hash', function(req, res) {
return Robohash.randomBot(robostore, function(err, canvas) {
var stream;
if (err != null) {
log.error(err);
return res.end();
} else if (canvas != null) {
stream = canvas.createPNGStream();
stream.on('data', function(chunk) {
return res.write(chunk);
});
return stream.on('end', function() {
return res.end();
});
} else {
return res.end();
}
});
});
app.listen(3000);
log.info("listening at port 3000");
console.log("open browser to http://localhost:3000");
}).call(this);