diff options
| author | Adam Soltys <[email protected]> | 2012-11-11 21:57:11 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2012-11-11 21:57:11 -0800 |
| commit | 81b30afabd1736e3dec4bb05c377b2d28317c2fe (patch) | |
| tree | dd71cb80284d29be0e635f95025e46f24b1fb94b /app.coffee | |
| parent | 3e900e0bba211c2bbf2bb10c85a82dd9ce6943f0 (diff) | |
| download | coinos-server-81b30afabd1736e3dec4bb05c377b2d28317c2fe.tar.gz coinos-server-81b30afabd1736e3dec4bb05c377b2d28317c2fe.zip | |
Save calculator params to database
Diffstat (limited to 'app.coffee')
| -rw-r--r-- | app.coffee | 32 |
1 files changed, 31 insertions, 1 deletions
@@ -10,6 +10,11 @@ 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((err, req, res, next) -> + res.status(500) + res.render('error', error: err ) +) app.get('/', (req, res) -> res.render('index', js: (-> global.js), css: (-> global.css)) @@ -44,9 +49,12 @@ app.get('/transactions/:login', (req, res) -> ) app.get('/ticker', (req, res) -> + symbol = req.params.symbol + symbol or= 'virtexCAD' + options = host: 'bitcoincharts.com', - path: '/t/depthcalc.json?symbol=virtexCAD&type=bid&amount=1000¤cy=true' + path: '/t/depthcalc.json?symbol=' + symbol + '&type=bid&amount=1000¤cy=true' require('http').get(options, (r) -> r.setEncoding('utf-8') @@ -56,6 +64,28 @@ app.get('/ticker', (req, res) -> ) ) +app.post('/create', (req, res) -> + connection = require('mysql').createConnection(config.database) + + connection.connect() + connection.query(""" + INSERT INTO users + (login, name, address, commission) + VALUES + (?, ?, ?, ?) + """, + [ + req.body.login, + req.body.name, + req.body.address, + req.body.commission + ], (err, rows) -> + connection.end() + res.writeHead(302, 'Location': '/' + req.body.login) + res.end() + ) +) + app.get('/:client', (req, res) -> res.render('calculator', client: req.params.client, |
