Minor fixes to closing proxy request
This commit is contained in:
@@ -2,7 +2,7 @@ const http = require('http');
|
||||
const https = require('https');
|
||||
|
||||
const HOST = 'localhost';
|
||||
const PORT = 3000;
|
||||
const PORT = 8888;
|
||||
const MAX_REDIRECTS = 5;
|
||||
|
||||
function setCorsHeaders(res) {
|
||||
@@ -20,6 +20,7 @@ function fetchWithRedirects(targetUrl, options, redirectCount = 0) {
|
||||
const req = httpClient.request(targetUrl, options, (res) => {
|
||||
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
||||
if (redirectCount >= MAX_REDIRECTS) {
|
||||
req.end();
|
||||
return reject(new Error('Too many redirects'));
|
||||
}
|
||||
|
||||
@@ -28,6 +29,7 @@ function fetchWithRedirects(targetUrl, options, redirectCount = 0) {
|
||||
const redirectUrl = new URL(res.headers.location, targetUrl);
|
||||
return resolve(fetchWithRedirects(redirectUrl, options, redirectCount + 1));
|
||||
} catch (error) {
|
||||
req.end();
|
||||
return reject(new Error(`Invalid URL in redirect: ${error.message}`));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user