forked from zhaojun-sh/dcrm-webwallet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
58 lines (47 loc) · 1.73 KB
/
app.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
const http = require('http')
const https = require('https')
const express = require('express')
const app = express()
const fs = require('fs')
const net = require('net')
const bodyParser = require('body-parser')
const httpsPort = 8086
const httpPort = 8087
const privateKey = fs.readFileSync('./server/keys/privkey.pem', 'utf-8')
const cretificats = fs.readFileSync('./server/keys/cert.pem', 'utf-8')
const credentials = {key: privateKey, cert: cretificats}
app.use(express.static(require('path').join(__dirname, 'public')))
app.all('*', function (req, res, next) {
res.header('Access-Control-Allow-Origin', '*')
res.header('Access-Control-Allow-Headers', 'X-Requested-With')
res.header('Access-Control-Allow-Methods', 'PUT,POST,GET,DELETE,OPTIONS')
res.header('X-Powered-By', '3.2.1')
res.header('Content-Type', 'application/json;charset=utf-8')
next()
})
app.use(bodyParser.json({limit: '50mb'}))
app.use(bodyParser.urlencoded({limit: '50mb', extended: true}))
let transferInfo = require('./server/transferInfo')
let lilo = require('./server/lilo')
app.use('/transfer', transferInfo)
app.use('/lilo', lilo)
const httpsServer = https.createServer(credentials, app)
httpsServer.listen(httpsPort)
const httpserver = http.createServer(app).listen(httpPort)
net.createServer(function (socket) {
socket.once('data', function (buf) {
// console.log(buf[0])
var address = buf[0] === 22 ? httpsPort : httpPort
var proxy = net.createConnection(address, function() {
proxy.write(buf)
socket.pipe(proxy).pipe(socket); })
proxy.on('error', function(err) {
console.log(err)
})
})
socket.on('error', function(err) {
console.log(err)
})
// console.log('success')
}, app).listen(8085)
// console.log(credentials)