-
Notifications
You must be signed in to change notification settings - Fork 9
/
app.coffee
98 lines (82 loc) · 2.22 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
express = require('express')
path = require('path')
engines = require('consolidate')
merchants = require("./routes/merchants")
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(app.router)
routes =
"/": 'index'
"/about": 'about'
"/exchangers": 'exchangers'
"/exchangers/join": 'join'
"/merchants": 'merchants'
"/merchants/signup": 'signup'
"/contact": '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)
app.get('/merchants2', merchants.list)
app.post('/contact', (req, res) ->
nodemailer = require("nodemailer")
smtpTransport = nodemailer.createTransport("SMTP",
service: "Gmail",
auth:
user: require('./config').user
pass: require('./config').pass
)
mailOptions =
from: "Adam Soltys <[email protected]>",
to: "[email protected]",
subject: "Bitcoin Co-op Contact Form",
html: JSON.stringify(req.body)
smtpTransport.sendMail(mailOptions, (error, response) ->
console.log(error) if(error)
smtpTransport.close()
)
res.render('thanks',
js: (-> global.js),
css: (-> global.css),
layout: 'layout'
)
)
app.get('/ticker', (req, res) ->
options =
host: 'bitcoincharts.com',
path: "/t/depthcalc.json?symbol=#{req.query.symbol}&type=#{req.query.type}&amount=#{req.query.amount}¤cy=true"
require('http').get(options, (r) ->
r.setEncoding('utf-8')
r.on('data', (chunk) ->
try
exchange = req.query.amount / JSON.parse(chunk).out
exchange = (Math.ceil(exchange * 100) / 100).toString()
catch e
exchange = ""
res.writeHead(200,
'Content-Length': exchange.length,
'Content-Type': 'text/plain')
res.write(exchange)
res.end()
)
)
)
app.use((err, req, res, next) ->
res.status(500)
console.log(err)
res.end()
)
app.listen(3002)