-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.coffee
57 lines (46 loc) · 1.35 KB
/
app.coffee
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
Log = require('log')
log = new Log Log.DEBUG
Express = require('express')
app = Express.createServer()
# init robohash & robostore
Robohash = require('./lib/robohash')
Robostore = require('./lib/robostore')
robostore = Robostore.getStorage "#{__dirname}/data/robostore"
# server configuration
app.configure ->
app.set 'views', "#{__dirname}/views"
app.set 'view engine', 'jade'
app.use Express.bodyParser()
app.use Express.methodOverride()
app.configure 'development', ->
app.use Express.errorHandler {
dumpExceptions: true
showStack: true
}
app.configure 'production', ->
app.use Express.errorHandler()
app.configure ->
app.use app.router
app.use Express.static "#{__dirname}/public"
app.get '/', (req, res) ->
res.render 'index', {
size: 100
rows: 8
cols: 8
}
app.get '/:hash', (req, res) ->
# TODO: use hash to build bot
# for now, just server a random bot
Robohash.randomBot robostore, (err, canvas) ->
if err?
log.error err
res.end()
else if canvas?
stream = canvas.createPNGStream()
stream.on 'data', (chunk) -> res.write chunk
stream.on 'end', -> res.end()
else
res.end()
app.listen 3000
log.info "listening at port 3000"
console.log "open browser to http://localhost:3000"