-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
65 lines (56 loc) · 1.7 KB
/
Copy pathserver.js
File metadata and controls
65 lines (56 loc) · 1.7 KB
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
57
58
59
60
61
62
63
64
65
const assert = require('assert');
const { URL } = require('url');
const express = require('express');
const next = require('next');
// var express_graphql = require('express-graphql');
// var { buildSchema } = require('graphql');
const bitcoin = require('bitcoin');
const safync = require('./safync');
const pMap = require('p-map');
const { rangeRight } = require('lodash');
const routes = require('./routes');
const pgp = require('pg-promise');
const postgraphile = require('postgraphile');
const config = require('./config');
require('dotenv').config();
const dev = process.env.NODE_ENV !== 'production';
const port = +(process.env.PORT || 3000);
const app = next({ dev });
const handler = routes.getRequestHandler(app);
// const handle = app.getRequestHandler();
function urlToBitcoinOptions(url) {
return {
host: url.hostname || 'localhost',
port: url.port,
user: url.username || 'user',
pass: url.password,
};
}
const { BITCOIND_RPC_URL } = process.env;
const bitcoinRpc = new bitcoin.Client(urlToBitcoinOptions(new URL(BITCOIND_RPC_URL)));
safync.applyTo(bitcoinRpc, 'cmd');
app
.prepare()
.then(() => {
const server = express();
server.use(
postgraphile.default(config.databaseUrl, 'public', {
watchPg: process.env.NODE_ENV !== 'production',
graphiql: true,
showErrorStack: true,
extendedErrors: ['hint', 'detail', 'errcode'],
})
);
server.use(handler);
// server.get('*', (req, res) => {
// return handle(req, res);
// });
server.listen(port, err => {
if (err) throw err;
console.log('> Ready on http://localhost:3000 !');
});
})
.catch(ex => {
console.error(ex.stack);
process.exit(1);
});