aboutsummaryrefslogtreecommitdiffstats
path: root/app.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2018-01-23 19:11:09 -0800
committerAdam Soltys <[email protected]>2018-01-23 19:11:09 -0800
commit8808b8e88bff57665ff6bf9a066def410ada1817 (patch)
treee85b974599b1fb8b1fc947143dfa995ea4e5562d /app.js
parent190aeef469c7b15c820cd6775d9c1407b5b5f247 (diff)
downloadcoinos-server-8808b8e88bff57665ff6bf9a066def410ada1817.tar.gz
coinos-server-8808b8e88bff57665ff6bf9a066def410ada1817.zip
graphql endpoint
Diffstat (limited to 'app.js')
-rw-r--r--app.js50
1 files changed, 47 insertions, 3 deletions
diff --git a/app.js b/app.js
index 68bfcffb..940a4600 100644
--- a/app.js
+++ b/app.js
@@ -5,6 +5,40 @@ import passport from './passport'
import cache from './cache'
import dotenv from 'dotenv'
import ba from 'bitcoinaverage'
+import fs from 'fs'
+import grpc from 'grpc'
+import { graphqlExpress, graphiqlExpress } from 'apollo-server-express'
+const { makeExecutableSchema } = require('graphql-tools');
+
+// Some fake data
+const books = [
+ {
+ title: "Harry Potter and the Sorcerer's stone",
+ author: 'J.K. Rowling',
+ },
+ {
+ title: 'Jurassic Park',
+ author: 'Michael Crichton',
+ },
+];
+
+// The GraphQL schema in string form
+const typeDefs = `
+ type Query { books: [Book] }
+ type Book { title: String, author: String }
+`;
+
+// The resolvers
+const resolvers = {
+ Query: { books: () => books },
+};
+
+// Put together a schema
+const schema = makeExecutableSchema({
+ typeDefs,
+ resolvers,
+});
+
dotenv.config()
require('dotenv').config()
@@ -21,7 +55,11 @@ const l = console.log
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' })
+ const lnrpc = await require('lnrpc')({ server: 'localhost:10001' })
+ const adminMacaroon = fs.readFileSync('/home/adam/.lnd/data/core_test/admin.macaroon');
+ const meta = new grpc.Metadata();
+ meta.add('macaroon', adminMacaroon.toString('hex'));
+
app.get('/users.json', transactions.index)
app.post('/login', users.login)
@@ -32,10 +70,9 @@ const l = console.log
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}))
+ res.json(await lnrpc.walletBalance({witness_only: true}, meta))
})
let fetchRates
@@ -50,6 +87,13 @@ const l = console.log
res.json(app.get('rates'))
})
+ app.use('/graphql', bodyParser.json(), graphqlExpress({
+ schema,
+ context: {},
+ }))
+
+ app.use('/graphiql', graphiqlExpress({ endpointURL: '/graphql' }))
+
app.use(function (err, req, res, next) {
res.status(500)
res.send('An error occurred')