-
Notifications
You must be signed in to change notification settings - Fork 42
/
app.coffee
81 lines (67 loc) · 2.2 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
express = require('express')
path = require('path')
engines = require('consolidate')
passport = require('./passport')
calculator = require("./routes/calculator")
sessions = require("./routes/sessions")(passport)
transactions = require("./routes/transactions")
users = require("./routes/users")(sessions)
RedisStore = require('connect-redis')(express)
sessionStore = new RedisStore(ttl: 172800)
app = express()
app.enable('trust proxy')
app.engine('html', require('mmm').__express)
app.set('view engine', 'html')
app.set('views', __dirname + '/views')
app.use(express.static(__dirname + '/public'))
app.use(require('connect-assets')(src: 'public'))
app.use(express.bodyParser())
app.use(express.cookieParser())
app.use(express.session(secret: 'weareallmadeofstars', store: sessionStore, key: 'vanbtc.sid'))
app.use(passport.initialize())
app.use(passport.session())
app.use(app.router)
routes =
"/": 'main/index'
"/about": 'main/about'
"/exchangers": 'main/exchangers'
"/exchangers/join": 'main/join'
"/merchants": 'main/merchants'
"/merchants/signup": 'main/signup'
"/contact": 'main/contact'
for route, view of routes
((route, view) ->
app.get(route, (req, res) ->
res.render(view,
js: (-> global.js),
css: (-> global.css),
layout: 'layout'
)
)
)(route, view)
authorize = (req, res, next) ->
if req.params.user is req.user?.username or
req.user?.username is 'admin'
return next()
res.redirect('/login')
app.get('/setup', calculator.new)
app.get('/calculator', calculator.show)
app.get('/ticker', calculator.ticker)
app.get('/login', sessions.new)
app.post('/login', sessions.create)
app.get('/logout', sessions.destroy)
app.get('/:user.json', authorize, users.json)
app.get('/:user', authorize, users.show)
app.get('/users/new', users.new)
app.post('/users', users.create)
app.get('/:user/edit', authorize, users.edit)
app.post('/:user/update', authorize, users.update)
app.get('/:user/transactions.json', authorize, transactions.json)
app.post('/:user/transactions', authorize, transactions.create)
app.get('/:user/report', authorize, transactions.index)
app.use((err, req, res, next) ->
res.status(500)
console.log(err)
res.end()
)
app.listen(3000)