fix-cert-download

This commit is contained in:
unknown
2025-04-06 12:16:10 +08:00
parent e5d80e01b6
commit c57d90b62f
3 changed files with 51 additions and 19 deletions

View File

@@ -98,7 +98,7 @@ var readline = require('readline');
var iconv = require('iconv-lite'); var iconv = require('iconv-lite');
var request = require('request'); var request = require('request');
const cors = require('cors'); const cors = require('cors');
var syncRequest = require('sync-request'); const axios = require('axios');
var globalQPSControl = {} var globalQPSControl = {}
function init(cb){ function init(cb){
@@ -588,24 +588,23 @@ async function daemon_start() {
}) })
} }
var mixioServer = function() { var mixioServer = async function() {
var keyPath = HTTPS_PRIVATE_PEM var keyPath = HTTPS_PRIVATE_PEM
var crtPath = HTTPS_CRT_FILE var crtPath = HTTPS_CRT_FILE
var privateKey = "" var privateKey = ""
var certificate = "" var certificate = ""
// if keyPath and crtPath are http/https, first download to configs/certs/
var privateKeyFileName = keyPath.split("/").pop()
var crtFileName = crtPath.split("/").pop()
if (keyPath.indexOf("http") == 0) { if (keyPath.indexOf("http") == 0) {
console.log("[INFO] Downloading private key from", keyPath)
var filePath = "config/certs/" + privateKeyFileName
// 如果存在就覆盖
if (fs.existsSync(filePath)) {
fs.unlinkSync(filePath)
}
// 下载文件
try{ try{
var body = syncRequest('GET', keyPath).getBody() var privateKeyFileName = keyPath.split("/").pop()
console.log("[INFO] Downloading private key from", keyPath)
var filePath = "config/certs/" + privateKeyFileName
// 如果存在就覆盖
if (fs.existsSync(filePath)) {
fs.unlinkSync(filePath)
}
// 下载文件
var resp = await axios.get(keyPath)
body = resp.data
// 不存在就创建 // 不存在就创建
fs.writeFileSync(filePath, body, 'utf8') fs.writeFileSync(filePath, body, 'utf8')
privateKey = fs.readFileSync(filePath, 'utf8') privateKey = fs.readFileSync(filePath, 'utf8')
@@ -626,13 +625,15 @@ var mixioServer = function() {
} }
} }
if (crtPath.indexOf("http") == 0) { if (crtPath.indexOf("http") == 0) {
console.log("[INFO] Downloading certificate from", crtPath)
var filePath = "config/certs/" + crtFileName
if (fs.existsSync(filePath)) {
fs.unlinkSync(filePath)
}
try{ try{
var body = syncRequest('GET', crtPath).getBody() var crtFileName = crtPath.split("/").pop()
console.log("[INFO] Downloading certificate from", crtPath)
var filePath = "config/certs/" + crtFileName
if (fs.existsSync(filePath)) {
fs.unlinkSync(filePath)
}
var resp = await axios.get(crtPath)
body = resp.data
fs.writeFileSync(filePath, body, 'utf8') fs.writeFileSync(filePath, body, 'utf8')
certificate = fs.readFileSync(filePath, 'utf8') certificate = fs.readFileSync(filePath, 'utf8')
console.log("[INFO] Certificate downloaded to", filePath) console.log("[INFO] Certificate downloaded to", filePath)

30
package-lock.json generated
View File

@@ -9,6 +9,7 @@
"version": "1.10.0", "version": "1.10.0",
"dependencies": { "dependencies": {
"aedes": "^0.51.3", "aedes": "^0.51.3",
"axios": "^0.27.0",
"cors": "^2.8.5", "cors": "^2.8.5",
"ejs": "^3.1.10", "ejs": "^3.1.10",
"express": "^4.21.2", "express": "^4.21.2",
@@ -852,6 +853,16 @@
"integrity": "sha512-lHe62zvbTB5eEABUVi/AwVh0ZKY9rMMDhmm+eeyuuUQbQ3+J+fONVQOZyj+DdrvD4BY33uYniyRJ4UJIaSKAfw==", "integrity": "sha512-lHe62zvbTB5eEABUVi/AwVh0ZKY9rMMDhmm+eeyuuUQbQ3+J+fONVQOZyj+DdrvD4BY33uYniyRJ4UJIaSKAfw==",
"license": "MIT" "license": "MIT"
}, },
"node_modules/axios": {
"version": "0.27.0",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.27.0.tgz",
"integrity": "sha512-XV/WrPxXfzgZ8j4lcB5i6LyaXmi90yetmV/Fem0kmglGx+mpY06CiweL3YxU6wOTNLmqLUePW4G8h45nGZ/+pA==",
"deprecated": "Formdata complete broken, incorrect build size",
"dependencies": {
"follow-redirects": "^1.14.9",
"form-data": "^4.0.0"
}
},
"node_modules/balanced-match": { "node_modules/balanced-match": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
@@ -2300,6 +2311,25 @@
"node": ">= 0.8" "node": ">= 0.8"
} }
}, },
"node_modules/follow-redirects": {
"version": "1.15.9",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz",
"integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==",
"funding": [
{
"type": "individual",
"url": "https://github.com/sponsors/RubenVerborgh"
}
],
"engines": {
"node": ">=4.0"
},
"peerDependenciesMeta": {
"debug": {
"optional": true
}
}
},
"node_modules/for-in": { "node_modules/for-in": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz", "resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz",

View File

@@ -1,6 +1,7 @@
{ {
"dependencies": { "dependencies": {
"aedes": "^0.51.3", "aedes": "^0.51.3",
"axios": "^0.27.0",
"cors": "^2.8.5", "cors": "^2.8.5",
"ejs": "^3.1.10", "ejs": "^3.1.10",
"express": "^4.21.2", "express": "^4.21.2",