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
|
var express = require('express')
, http = require('http')
, path = require('path')
, engines = require('consolidate')
, config = require('./config')
, app = express();
app.engine('html', engines.hogan);
app.set('view engine', 'html');
app.set('views', __dirname + '/views');
app.use(express.static(path.join(__dirname, 'public')));
app.get('/', function(req, res) {
res.render('index');
});
app.get('/report', function(req, res) {
res.render('report');
});
app.get('/calculator', function(req, res) {
res.render('calculator');
});
app.get('/client/:login', function(req, res) {
var connection = require('mysql').createConnection(config.database);
connection.connect();
connection.query("SELECT name, address, commission, logo FROM users WHERE login = ?",
[req.params.login], function(err, rows) {
res.write(JSON.stringify(rows));
connection.end();
res.end();
}
);
});
app.get('/ticker', function(req, res) {
var options = {
host: 'bitcoincharts.com',
path: '/t/depthcalc.json?symbol=virtexCAD&type=bid&amount=1000¤cy=true'
}
require('http').get(options, function(r) {
r.setEncoding('utf-8');
r.on('data', function(chunk) {
res.send(chunk);
});
});
});
app.get('/:client', function(req, res) {
res.render('calculator', { client: req.params.client });
});
app.listen(3000);
|