diff options
| author | Adam Soltys <[email protected]> | 2018-01-22 16:17:20 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2018-01-22 16:17:20 -0800 |
| commit | 190aeef469c7b15c820cd6775d9c1407b5b5f247 (patch) | |
| tree | 033d41673f726a50a283e4ceff1d4aa1857bbcc6 /app.js | |
| parent | e73c5018549c338e1dd5be8c0d82e1765ee4741a (diff) | |
| download | coinos-server-190aeef469c7b15c820cd6775d9c1407b5b5f247.tar.gz coinos-server-190aeef469c7b15c820cd6775d9c1407b5b5f247.zip | |
wrap app in async function
Diffstat (limited to 'app.js')
| -rw-r--r-- | app.js | 82 |
1 files changed, 43 insertions, 39 deletions
@@ -8,50 +8,54 @@ import ba from 'bitcoinaverage' dotenv.config() require('dotenv').config() +const l = console.log -const app = express() -app.enable('trust proxy') -app.use(require('./blockcypher')) -app.use(bodyParser.urlencoded({ extended: true })) -app.use(bodyParser.json()) -app.use(cookieParser()) -app.use(passport.initialize()) +;(async () => { + const app = express() + app.enable('trust proxy') + app.use(bodyParser.urlencoded({ extended: true })) + app.use(bodyParser.json()) + app.use(cookieParser()) + app.use(passport.initialize()) -const users = require('./routes/users') -const transactions = require('./routes/transactions') -const restClient = ba.restfulClient(process.env.BITCOINAVERAGE_PUBLIC, process.env.BITCOINAVERAGE_SECRET) + const users = require('./routes/users') + const transactions = require('./routes/transactions') + const restClient = ba.restfulClient(process.env.BITCOINAVERAGE_PUBLIC, process.env.BITCOINAVERAGE_SECRET) + const lnrpc = await require('lnrpc')({ server: 'localhost:10009' }) -app.get('/users.json', transactions.index) -app.post('/login', users.login) -app.post('/users', users.create) -app.get('/verify/:token', users.verify) -app.post('/:user', users.update) -// app.post('/:user/transactions', transactions.create) -app.get('/:user/transactions', transactions.index) -app.post('/transactions/:txid', transactions.update) -app['delete']('/:user/transactions/:txid', transactions['delete']) -app.get('/:user.json', users.json) -app.get('/secret', passport.authenticate('jwt', { session: false }), users.secret) - -let fetchRates -(fetchRates = () => { - restClient.tickerGlobalPerSymbol('BTCUSD', (data) => { - app.set('rates', JSON.parse(data)) + app.get('/users.json', transactions.index) + app.post('/login', users.login) + app.post('/users', users.create) + app.get('/verify/:token', users.verify) + app.post('/:user', users.update) + // app.post('/:user/transactions', transactions.create) + app.get('/:user/transactions', transactions.index) + app.post('/transactions/:txid', transactions.update) + app['delete']('/:user/transactions/:txid', transactions['delete']) + app.get('/:user.json', users.json) + app.get('/secret', passport.authenticate('jwt', { session: false }), users.secret) + app.get('/balance', async (req, res) => { + res.json(await lnrpc.walletBalance({witness_only: true})) }) - setTimeout(fetchRates, 120000) -})() - -app.get('/rates', (req, res) => { - res.json(app.get('rates')) -}) -app.use(function (err, req, res, next) { - res.status(500) - res.send('An error occurred') - console.error(err.stack) - return res.end() -}) + let fetchRates + (fetchRates = () => { + restClient.tickerGlobalPerSymbol('BTCUSD', (data) => { + app.set('rates', JSON.parse(data)) + }) + setTimeout(fetchRates, 120000) + })() -app.listen(3000) + app.get('/rates', (req, res) => { + res.json(app.get('rates')) + }) + app.use(function (err, req, res, next) { + res.status(500) + res.send('An error occurred') + console.error(err.stack) + return res.end() + }) + app.listen(3000) +})() |
