-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.coffee
61 lines (49 loc) · 1.82 KB
/
index.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
58
59
60
61
express = require 'express'
bodyParser = require 'body-parser'
cors = require 'cors'
app = express()
app.use(cors(
origin: (origin, callback) ->
if origin
allow = origin.match(/\.kosendj-bu\.in\//) != null
if app.get('env') == "development"
allow = allow || origin.match(/localhost/) != null
callback(null, allow)
else
callback(null, false)
))
http = require('http').Server app
io = require('socket.io')(http)
redis = require 'redis'
redis_url = process.env.REDIS_URL or process.env.REDISTOGO_URL or process.env.REDISCLOUD_URL
unless redis_url
console.log '$REDIS_URL, $REDISTOGO_URL, $REDISCLOUD_URL not specified; falling back to redis://localhost:6379'
redis_url = 'redis://localhost:6379'
process.globals = {}
rtg = require('url').parse redis_url
process.globals.redis = redis.createClient rtg.port, rtg.hostname
if rtg.auth
process.globals.redis.auth rtg.auth.split(':')[1]
process.globals.io = io
app.set 'views', "#{__dirname}/views"
app.set 'view engine', 'jade'
app.use bodyParser.urlencoded({extended: true})
app.use express.static("#{__dirname}/build")
app.use express.static("#{__dirname}/public")
app.get '/', (req, res)-> res.render 'index'
app.get '/gifs', require('./lib/gif').index
app.post '/gifs', require('./lib/gif').add
app.get '/gifs/queue', require('./lib/queue').index
unless process.env.CAMO_URL
app.get /^\/gifs\/retrieve\/(.+)$/, require('./lib/gif').retrieve
app.get '/screen', (req, res)-> res.render 'screen'
app.get '/bpm', require('./lib/bpm').get
app.get '/usage', (req, res)-> res.render 'usage'
app.post '/name', require('./lib/screen').name
io.on 'connection', require './lib/socket'
require './lib/twitter'
port = if process.env.PORT
parseInt(process.env.PORT, 10)
else
3000
http.listen port, -> console.log "Listening at port #{port}"