forked from CounterpartyXCP/indexd-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (31 loc) · 1.24 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
// dotenv at CONFIG_FILE or .env
let dotenv = require('dotenv')
require('dotenv').load({path: process.env.CONFIG_FILE ? process.env.CONFIG_FILE : '.env'})
let TESTNET = (process.env.TESTNET === '1' || (process.env.TESTNET && process.env.TESTNET.toLowerCase() === 'true'))
let REGTEST = (process.env.REGTEST === '1' || (process.env.REGTEST && process.env.REGTEST.toLowerCase() === 'true'))
if (TESTNET && REGTEST) {
throw new Error('Cannot specify REGTEST and TESTNET at the same time')
}
let debug = require('debug')('index')
let express = require('express')
let service = require('./lib/service')
let api = require('./lib/express')
let app = express()
let cors = require('cors')
if (process.env.CORS === '*') {
app.use(cors())
} else if (process.env.CORS) {
app.use(cors({ origin: process.env.CORS }))
}
// run the service
debug(`Initializing blockchain connection${["", " (for testnet)", " (for regtest)"][(TESTNET?1:0)+(REGTEST?2:0)]}`)
service((err, adapter) => {
if (err) {
return debug('Initialization failed:', err)
}
// start the API server
debug('starting API server')
app.use(api(adapter, {testnet: TESTNET, regtest: REGTEST}))
app.listen(process.env.SERVER_PORT);
debug("App listening on port "+process.env.SERVER_PORT);
})