forked from DeckerSU/insight-ui-komodo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
86 lines (79 loc) · 2.58 KB
/
main.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
80
81
82
83
84
85
86
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const fs = require('fs');
let app = express();
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'X-Requested-With');
res.header('Access-Control-Allow-Credentials', 'true');
res.header('Access-Control-Allow-Headers', 'Content-Type');
res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS');
next();
});
app.use(bodyParser.json({ limit: '5mb' })); // support json encoded bodies
app.use(bodyParser.urlencoded({
limit: '5mb',
extended: true,
})); // support encoded bodies
// router
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname + '/public/index.html'));
});
app.get('/status', (req, res) => {
res.sendFile(path.join(__dirname + '/public/index.html'));
});
app.get('/stats', (req, res) => {
res.sendFile(path.join(__dirname + '/public/index.html'));
});
app.get('/messages/verify', (req, res) => {
res.sendFile(path.join(__dirname + '/public/index.html'));
});
app.get('/tx/send/*', (req, res) => {
res.sendFile(path.join(__dirname + '/public/index.html'));
});
app.get('/blocks/*', (req, res) => {
res.sendFile(path.join(__dirname + '/public/index.html'));
});
app.get('/block/*', (req, res) => {
res.sendFile(path.join(__dirname + '/public/index.html'));
});
app.get('/block-index/*', (req, res) => {
res.sendFile(path.join(__dirname + '/public/index.html'));
});
app.get('/blocks-date/*', (req, res) => {
res.sendFile(path.join(__dirname + '/public/index.html'));
});
app.get('/tx/*', (req, res) => {
res.sendFile(path.join(__dirname + '/public/index.html'));
});
app.get('/address/*', (req, res) => {
res.sendFile(path.join(__dirname + '/public/index.html'));
});
app.get('/charts/*', (req, res) => {
res.sendFile(path.join(__dirname + '/public/index.html'));
});
app.get('/search/*', (req, res) => {
res.sendFile(path.join(__dirname + '/public/index.html'));
});
app.use('/', express.static(path.join(__dirname, 'public')));
let server;
const config = {
ip: 'localhost',
https: false,
port: 8888,
};
if (config.https) {
const options = {
key: fs.readFileSync('certs/priv.pem'),
cert: fs.readFileSync('certs/cert.pem'),
};
server = require('https')
.createServer(options, app)
.listen(config.port, config.isDev ? 'localhost' : config.ip);
} else {
server = require('http')
.createServer(app)
.listen(config.port, config.isDev ? 'localhost' : config.ip);
}
console.log(`Insight Common UI server is running`);