mirror of
https://github.com/NginxProxyManager/nginx-proxy-manager.git
synced 2025-11-13 05:45:15 +00:00
https.get
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
import express from "express";
|
import express from "express";
|
||||||
import { debug, express as logger } from "../logger.js";
|
import { debug, express as logger } from "../logger.js";
|
||||||
import pjson from "../package.json" with { type: "json" };
|
import pjson from "../package.json" with { type: "json" };
|
||||||
|
import https from "node:https";
|
||||||
|
import { ProxyAgent } from "proxy-agent";
|
||||||
|
|
||||||
const router = express.Router({
|
const router = express.Router({
|
||||||
caseSensitive: true,
|
caseSensitive: true,
|
||||||
@@ -24,15 +26,37 @@ router
|
|||||||
*/
|
*/
|
||||||
.get(async (req, res, next) => {
|
.get(async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(
|
const agent = new ProxyAgent();
|
||||||
"https://api.github.com/repos/NginxProxyManager/nginx-proxy-manager/releases/latest"
|
const url = "https://api.github.com/repos/NginxProxyManager/nginx-proxy-manager/releases/latest";
|
||||||
);
|
|
||||||
|
|
||||||
if (!response.ok) {
|
const data = await new Promise((resolve, reject) => {
|
||||||
throw new Error(`GitHub API returned ${response.status}`);
|
https
|
||||||
}
|
.get(url, { agent }, (response) => {
|
||||||
|
if (response.statusCode !== 200) {
|
||||||
|
reject(new Error(`GitHub API returned ${response.statusCode}`));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
response.setEncoding("utf8");
|
||||||
|
let raw_data = "";
|
||||||
|
|
||||||
|
response.on("data", (chunk) => {
|
||||||
|
raw_data += chunk;
|
||||||
|
});
|
||||||
|
|
||||||
|
response.on("end", () => {
|
||||||
|
try {
|
||||||
|
resolve(JSON.parse(raw_data));
|
||||||
|
} catch (err) {
|
||||||
|
reject(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.on("error", (err) => {
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
const data = await response.json();
|
|
||||||
const latestVersion = data.tag_name;
|
const latestVersion = data.tag_name;
|
||||||
|
|
||||||
const version = pjson.version.split("-").shift().split(".");
|
const version = pjson.version.split("-").shift().split(".");
|
||||||
|
|||||||
Reference in New Issue
Block a user