-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
71 lines (66 loc) · 2.08 KB
/
index.js
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
66
67
68
69
70
require('dotenv').config()
const express = require('express')
const ip = require('ip')
const app = express()
const cors = require("cors")
const bitsocketd = require('dvt-bitdb-core').bitsocketd
const config = {
"query": {
"v": 3,
"q": { "find": {} },
"r": {
"f": "[.[] | .out[] | .str]"
}
},
"host": process.env.sockserve_host ? process.env.sockserve_host : "http://127.0.0.1",
"port": Number.parseInt(process.env.sockserve_port ? process.env.sockserve_port : 3001)
};
config.url = config.host + ":" + config.port + "/s/";
var db
app.set('view engine', 'ejs')
app.use(express.static('public'))
app.use(cors())
app.enable("trust proxy")
app.get(/^\/channel\/(.+)/, function(req, res) {
let encoded = req.params[0]
let decoded = Buffer.from(encoded, 'base64').toString()
res.render('channel', {
bitserve_url: config.url,
code: decoded,
bitdb: process.env.same_domain_bitdb
})
});
app.get('/channel', function (req, res) {
res.render('channel', {
bitserve_url: config.url,
code: JSON.stringify(config.query, null, 2),
bitdb: process.env.same_domain_bitdb
})
});
app.get('/', function(req, res) {
res.redirect('/channel')
});
app.listen(config.port, () => {
console.log("######################################################################################");
console.log("#")
console.log("# SOCKSERVE: Bitsocket Microservice")
console.log("# Serving Transactions through HTTP...")
console.log("#")
console.log(`# Channel: ${ip.address()}:${config.port}/channel`);
console.log("#")
console.log("# Learn more at https://docs.fountainhead.cash")
console.log("#")
console.log("######################################################################################");
}
)
bitsocketd.init({
bit: {
host: process.env.zmq_outgoing_host ? process.env.zmq_outgoing_host : '0.0.0.0',
port: Number.parseInt(process.env.zmq_outgoing_port ? process.env.zmq_outgoing_port : 28339)
},
socket: {
port: process.env.sockserve_port ? process.env.sockserve_port : 3000,
app: app
},
heartbeat: 10
});