Files
cbsnexora/proxy.conf.js
T
Felix van HoveandGitHub b4503d34f3 fix: Improve login, server selection and proxy configuration (#2511)
No potentially malicious URLs referenced in markdown; added
servers stays in server selector list; the currently active server
is visible on the bottom right of smaller screens; a proxy configuration
can be provided now and works; a trailing slash in the added server
is no problem anymore, because it's removed.

FIXES: WEB-193
2025-06-11 11:32:36 -06:00

46 lines
1.2 KiB
JavaScript

'use strict';
const { HttpsProxyAgent } = require('https-proxy-agent');
/*
* API proxy configuration.
* This allows you to proxy HTTP request like `http.get('/api/stuff')` to another server/port.
* This is especially useful during app development to avoid CORS issues while running a local server.
* For more details and options, see https://github.com/angular/angular-cli#proxy-to-backend
*/
const proxyConfig = [
{
context: '/api',
pathRewrite: { '^/api': '' },
target: 'https://api.chucknorris.io',
changeOrigin: true,
secure: false
}
];
/*
* Configures a proxy agent for the API proxy if needed.
*/
function setupForProxy(proxyConfig) {
if (!Array.isArray(proxyConfig)) {
proxyConfig = [proxyConfig];
}
const proxyServer = process.env.http_proxy || process.env.HTTP_PROXY;
let agent = null;
if (proxyServer) {
console.log(`Using proxy server: ${proxyServer}`);
agent = new HttpsProxyAgent(proxyServer);
proxyConfig.forEach((entry) => {
entry.agent = agent;
});
} else {
console.warn('No proxy server configured. API requests will not be proxied.');
}
return proxyConfig;
}
module.exports = setupForProxy(proxyConfig);