Added proxy support for axios. (#6334)

This commit is contained in:
SamTV12345 2024-04-16 19:11:05 +02:00 committed by GitHub
parent 15f36a1350
commit 0b80e256b4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 41 additions and 10 deletions

View file

@ -100,7 +100,15 @@ export const HomePage = () => {
pluginsSocket!.on('results:search', (data: {
results: PluginDef[]
}) => {
if (Array.isArray(data.results) && data.results.length === 0) {
setPlugins(data.results)
} else {
useStore.getState().setToastState({
open: true,
title: "Error retrieving plugins",
success: false
})
}
})

View file

@ -27,6 +27,7 @@ import {ErrorCaused} from "./types/ErrorCaused";
import log4js from 'log4js';
import pkg from '../package.json';
import {checkForMigration} from "../static/js/pluginfw/installer";
import axios from "axios";
const settings = require('./utils/Settings');
@ -37,6 +38,28 @@ if (settings.dumpOnUncleanExit) {
wtfnode = require('wtfnode');
}
const addProxyToAxios = (url: URL) => {
axios.defaults.proxy = {
host: url.hostname,
port: Number(url.port),
protocol: url.protocol,
}
}
if(process.env['http_proxy']) {
console.log("Using proxy: " + process.env['http_proxy'])
addProxyToAxios(new URL(process.env['http_proxy']));
}
if (process.env['https_proxy']) {
console.log("Using proxy: " + process.env['https_proxy'])
addProxyToAxios(new URL(process.env['https_proxy']));
}
/*
* early check for version compatibility before calling
* any modules that require newer versions of NodeJS

View file

@ -1,7 +1,7 @@
'use strict';
const semver = require('semver');
const settings = require('./Settings');
const axios = require('axios');
import axios from 'axios';
const headers = {
'User-Agent': 'Etherpad/' + settings.getEpVersion(),
}
@ -17,7 +17,7 @@ let lastLoadingTime: number | null = null;
const loadEtherpadInformations = () => {
if (lastLoadingTime !== null && Date.now() - lastLoadingTime < updateInterval) {
return Promise.resolve(infos);
return infos;
}
return axios.get('https://static.etherpad.org/info.json', {headers: headers})
@ -29,10 +29,10 @@ const loadEtherpadInformations = () => {
}
lastLoadingTime = Date.now();
return await Promise.resolve(infos);
return infos;
})
.catch(async (err: Error) => {
return await Promise.reject(err);
throw err;
});
}
@ -43,15 +43,15 @@ exports.getLatestVersion = () => {
};
exports.needsUpdate = async (cb?: Function) => {
await loadEtherpadInformations()
.then((info:Infos) => {
if (semver.gt(info.latestVersion, settings.getEpVersion())) {
try {
const info = await loadEtherpadInformations()
if (semver.gt(info!.latestVersion, settings.getEpVersion())) {
if (cb) return cb(true);
}
}).catch((err: Error) => {
} catch (err) {
console.error(`Can not perform Etherpad update check: ${err}`);
if (cb) return cb(false);
});
}
};
exports.check = () => {