aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2018-03-20 17:03:46 +0000
committerAdam Soltys <[email protected]>2018-03-20 17:03:46 +0000
commit27cba8e4b054b6dde5b399e201d52b77b11a9a8a (patch)
tree19e5c2ab5f636a43e7d1e315d328b1f7bfde1f35
parentaca2da56939d6168bf8e02a9d112951abc3da927 (diff)
downloadcoinos-server-27cba8e4b054b6dde5b399e201d52b77b11a9a8a.tar.gz
coinos-server-27cba8e4b054b6dde5b399e201d52b77b11a9a8a.zip
refactor config
-rw-r--r--.gitignore1
-rw-r--r--blockcypher.js17
-rw-r--r--cache.js6
-rw-r--r--config/index.js.sample39
-rw-r--r--db.js5
-rw-r--r--index.js26
-rw-r--r--test.js20
7 files changed, 52 insertions, 62 deletions
diff --git a/.gitignore b/.gitignore
index 9d717be3..a5ff8ebe 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,3 +9,4 @@ db
config.js
.env
config/config.json
+config/index.js
diff --git a/blockcypher.js b/blockcypher.js
deleted file mode 100644
index 91adbc10..00000000
--- a/blockcypher.js
+++ /dev/null
@@ -1,17 +0,0 @@
-const proxyMiddleware = require('http-proxy-middleware')
-const proxyContext = '/blockcypher'
-
-const proxyOptions = {
- target: 'https://api.blockcypher.com',
- changeOrigin: true,
- pathRewrite: {
- '^/blockcypher/': '/'
- },
- onProxyReq: function(proxyReq, req, res) {
- var symbol
- symbol = indexOf.call(proxyReq.path, '?') >= 0 ? '&' : '?'
- return proxyReq.path += symbol + "token=" + config.blockcypher_token
- }
-}
-
-module.exports = proxyMiddleware(proxyContext, proxyOptions)
diff --git a/cache.js b/cache.js
deleted file mode 100644
index 645fd610..00000000
--- a/cache.js
+++ /dev/null
@@ -1,6 +0,0 @@
-module.exports = (req, res, next) => {
- if (req.path !== '/login') {
- res.setHeader("Cache-Control", "public, max-age=900")
- }
- return next()
-}
diff --git a/config/index.js.sample b/config/index.js.sample
new file mode 100644
index 00000000..d4a03230
--- /dev/null
+++ b/config/index.js.sample
@@ -0,0 +1,39 @@
+import db from './config.json'
+
+module.exports = {
+ db,
+ bitcoin: {
+ username: '',
+ password: '',
+ network: 'mainnet',
+ },
+ lna: {
+ server: 'localhost:10001',
+ tls: '/home/adam/.lnd/tls.cert',
+ macaroon: '/home/adam/.lnd/test.macaroon',
+ },
+ lnb: {
+ server: 'localhost:10002',
+ tls: '/home/adam/.lndb/tls.cert',
+ macaroon: '/home/adam/.lndb/test.macaroon',
+ },
+ auto: {
+ host: "localhost",
+ dialect: "mysql",
+ tables: ["users", "payments"],
+ logging: false,
+ directory: false,
+ operatorsAliases: false,
+ dialectOptions: {
+ timeout: 500000,
+ multipleStatements: true
+ },
+ pool: {
+ min: 0,
+ max: 25
+ },
+ retry: {
+ max: 5
+ }
+ }
+}
diff --git a/db.js b/db.js
index c10b925d..9b3cf11a 100644
--- a/db.js
+++ b/db.js
@@ -1,4 +1,4 @@
-import config from './config/config.json'
+import config from './config'
import Sequelize from 'sequelize'
import SequelizeAuto from 'sequelize-auto'
import { resolver, defaultArgs, defaultListArgs, attributeFields } from 'graphql-sequelize'
@@ -14,8 +14,7 @@ import {
} from 'graphql'
const Op = Sequelize.Op
-const l = console.log
-const conf = config[process.env.NODE_ENV]
+const conf = config.db[process.env.NODE_ENV]
const auto = new SequelizeAuto(
conf.database,
diff --git a/index.js b/index.js
index 9a81fc57..30aee547 100644
--- a/index.js
+++ b/index.js
@@ -16,7 +16,7 @@ import morgan from 'morgan'
import reverse from 'buffer-reverse'
import zmq from 'zmq'
-import cache from './cache'
+import config from './config'
import graphqlHTTP from 'express-graphql'
@@ -24,23 +24,17 @@ dotenv.config()
const l = console.log
;(async () => {
- const lna = await require('lnrpc')({ server: 'localhost:10001', tls: '/home/adam/.lnd/tls.cert' })
- const maca = fs.readFileSync('/home/adam/.lnd/test.macaroon')
- const meta = new grpc.Metadata()
- meta.add('macaroon', maca.toString('hex'))
- lna.meta = meta
+ const ln = async ({ server, tls, macaroon }) => {
+ const ln = await require('lnrpc')({ server, tls })
+ ln.meta = new grpc.Metadata()
+ ln.meta.add('macaroon', fs.readFileSync(macaroon).toString('hex'))
+ return ln
+ }
- const lnb = await require('lnrpc')({ server: 'localhost:10002', tls: '/home/adam/.lndb/tls.cert' })
- const macb = fs.readFileSync('/home/adam/.lndb/test.macaroon')
- const metab = new grpc.Metadata()
- metab.add('macaroon', macb.toString('hex'))
- lnb.meta = metab
+ const lna = await ln(config.lna)
+ const lnb = await ln(config.lnb)
- const bc = new core({
- username: 'adam',
- password: 'hk79c7dI8ysAHY42eglqrJLo9A8CoyvWINMAcwuPzhQ=',
- network: 'mainnet',
- })
+ const bc = new core(config.bitcoin)
const app = express()
app.enable('trust proxy')
diff --git a/test.js b/test.js
deleted file mode 100644
index ce3bf009..00000000
--- a/test.js
+++ /dev/null
@@ -1,20 +0,0 @@
-import core from 'bitcoin-core'
-import fs from 'fs'
-import grpc from 'grpc'
-
-const bc = new core({
- username: 'adam',
- password: 'hk79c7dI8ysAHY42eglqrJLo9A8CoyvWINMAcwuPzhQ=',
- network: 'mainnet',
-})
-
-;(async () => {
- const lna = await require('lnrpc')({ server: 'localhost:10001', tls: '/home/adam/.lnd/tls.cert' })
- const maca = fs.readFileSync('/home/adam/.lnd/test.macaroon')
- const meta = new grpc.Metadata()
- meta.add('macaroon', maca.toString('hex'))
- lna.meta = meta
- let i = await lna.getInfo({}, meta)
- console.log(i)
- console.log(await bc.getBalance())
-})()