Comparing version 2.0.6 to 2.0.7
const fs = require('fs'); | ||
const fs = require('fs-extra'); | ||
const path = require('path'); | ||
@@ -8,5 +8,5 @@ const chalk = require('chalk'); | ||
const crtFile = path.join(ctx.app.config.RC_DIR, 'feproxy.crt'); | ||
if (fs.existsSync(crtFile)) { | ||
if (await fs.exists(crtFile)) { | ||
ctx.set('content-type', 'application/octet-stream'); | ||
ctx.body = fs.readFileSync(crtFile); | ||
ctx.body = await fs.readFile(crtFile); | ||
} | ||
@@ -13,0 +13,0 @@ }; |
@@ -11,4 +11,6 @@ | ||
keepAlive: true, | ||
maxSockets: 6, | ||
keepAliveMsecs: 1000, | ||
keepAliveMsecs: 5000, | ||
maxSockets: 50, | ||
maxFreeSockets: 10, | ||
timeout: 60000, | ||
}; | ||
@@ -15,0 +17,0 @@ |
@@ -6,2 +6,7 @@ | ||
const agent = new https.Agent({ | ||
keepAlive: false, | ||
timeout: 10000, | ||
}); | ||
module.exports = app => { | ||
@@ -21,2 +26,3 @@ const getCertificate = ca(app.config); | ||
method: 'GET', | ||
agent, | ||
}, res => { | ||
@@ -49,14 +55,22 @@ res.on('error', () => {}); | ||
if (!serverMap[key]) { | ||
const isTrust = !isProxy || await isTrustHost(hostname, port); | ||
const pem = getCertificate(hostname, isTrust).pem; | ||
const server = serverMap[key] = https.createServer(pem, app.callback()); | ||
if (isProxy) { | ||
server.proxy = { | ||
hostname, | ||
port, | ||
}; | ||
} | ||
app.ws.listen({ server }); | ||
serverMap[key] = (async () => { | ||
const isTrust = !isProxy || await isTrustHost(hostname, port); | ||
const pem = getCertificate(hostname, isTrust).pem; | ||
const server = https.createServer(pem, app.callback()); | ||
if (isProxy) { | ||
server.proxy = { | ||
hostname, | ||
port, | ||
}; | ||
} | ||
app.ws.listen({ server }); | ||
serverMap[key] = server; | ||
})(); | ||
} | ||
if (serverMap[key] instanceof Promise) { | ||
await serverMap[key]; | ||
} | ||
return serverMap[key]; | ||
@@ -63,0 +77,0 @@ }, |
{ | ||
"name": "feproxy", | ||
"version": "2.0.6", | ||
"version": "2.0.7", | ||
"description": "An node proxy server for web development", | ||
@@ -5,0 +5,0 @@ "scripts": { |
842329
2926