This repository has been archived by the owner on Nov 27, 2022. It is now read-only.
forked from OriginProtocol/origin-playground
/
index.js
executable file
·79 lines (71 loc) · 2 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
71
72
73
74
75
76
77
78
79
import express from 'express'
import serveStatic from 'serve-static'
import { spawn } from 'child_process'
import Ganache from 'ganache-core'
import opener from 'opener'
import fs from 'fs'
import Web3 from 'web3'
import simpleIssuer from './issuer-services/_simple'
const HOST = process.env.HOST || 'localhost'
const app = express()
app.get('/', (req, res) => {
var html = fs.readFileSync(__dirname + '/public/dev.html').toString()
res.send(html.replace(/\{HOST\}/g, `http://${HOST}:8080/`))
})
app.use(serveStatic('public'))
try {
var { simpleApp } = require('./issuer-services/config.json')
simpleIssuer(app, { web3: new Web3(), simpleApp })
} catch(e) {
/* Ignore */
}
const startGanache = () =>
new Promise((resolve, reject) => {
try {
fs.mkdirSync('./data/db')
} catch (e) {
/* Ignore */
}
var server = Ganache.server({
total_accounts: 5,
default_balance_ether: 100,
db_path: 'data/db',
network_id: 999,
seed: 123,
mnemonic: "rival alley punch barrel baby other taxi cannon pause achieve caution race"
// blocktime: 3
})
server.listen(8545, err => {
if (err) {
return reject(err)
}
console.log('Ganache listening. Starting webpack...')
resolve()
})
})
async function start() {
await startGanache()
const webpackDevServer = spawn('./node_modules/.bin/webpack-dev-server', [
'--info=true',
'--port=8080',
'--host=0.0.0.0'
])
webpackDevServer.stdout.pipe(process.stdout)
webpackDevServer.stderr.pipe(process.stderr)
process.on('exit', () => webpackDevServer.kill())
const PORT = process.env.PORT || 3344
app.listen(PORT, () => {
console.log(`\nListening on host ${HOST}, port ${PORT}\n`)
setTimeout(() => {
try{
const url = `http://${HOST}:${PORT}`
console.log(`Opening Browser at ${url}`)
const browser = opener(url)
browser.unref();
}catch(err){
console.log("open browser", err.message);
}
}, 4500)
})
}
start()