-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
55 lines (45 loc) · 1.44 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
const express = require('express');
const fs = require('fs');
const path = require('path');
const server = require('./src/server');
//const auth0 = require('./src/server/middlewares/auth0');
// configure API
let app = express ();
app.use(server);
// configure client
let client;
if (app.get('env') == 'development') {
const createDevMiddleware = require ('webpack-dev-middleware');
const webpack = require ('webpack');
const webpackConfig = require ('./webpack.config.babel');
let webpackCompiler = webpack(webpackConfig);
let devMiddleWare = createDevMiddleware(webpackCompiler, {
publicPath: webpackConfig.output.publicPath,
});
app.use(devMiddleWare);
client = responseMiddleware(devMiddleWare.fileSystem);
} else {
app.use('/assets', express.static('./dist'));
client = responseMiddleware(fs);
}
app.get('*', client);
const port = process.env.PORT || 8000;
// start
app.listen(port, () => {
console.log('Server running on 8000');
let crypto = require('crypto');
let secp256k1 = require('secp256k1');
var privKey;
do {
privKey = crypto.randomBytes(32);
} while (!secp256k1.privateKeyVerify(privKey));
var pubKey = secp256k1.publicKeyCreate(privKey);
console.log('Public key for test purposes:', pubKey.toString('hex'));
});
// helpers
function responseMiddleware (fs) {
return function (req, res) {
let html = fs.readFileSync(path.resolve(__dirname, 'dist', 'index.html'));
res.send(html.toString());
}
}