-
Notifications
You must be signed in to change notification settings - Fork 16
/
main.js
59 lines (51 loc) · 1.57 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
const express = require('express');
const bodyParser = require('body-parser');
const compression = require('compression');
let api = require('./routes/api');
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: '1mb' })); // support json encoded bodies
app.use(bodyParser.urlencoded({
limit: '1mb',
extended: true,
})); // support encoded bodies
app.get('/', (req, res) => {
res.send('Electrum Proxy Server');
});
app.use(compression({
level: 9,
threshold: 0,
}));
app.use('/api', api);
let config = {
https: false,
};
let server;
process.argv.forEach((val, index) => {
if (val.indexOf('ip=') > -1) {
config.ip = val.replace('ip=', '');
} else if (val.indexOf('port=') > -1) {
config.port = val.replace('port=', '');
}
});
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 || 8118, config.ip || 'localhost');
} else {
server = require('http')
.createServer(app)
.listen(config.port || 8118, config.ip || 'localhost');
}
console.log(`Electrum Proxy Server is running at ${config.ip || 'localhost'}:${config.port || 8118}`);