Minor improvements to nodejs proxy

This commit is contained in:
WardPearce
2025-01-25 10:12:50 +13:00
parent c17184bd32
commit da5748ea8c
5 changed files with 10 additions and 23 deletions
+2 -2
View File
@@ -7,8 +7,8 @@ android {
applicationId "us.materialio.app"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 82
versionName "1.7.0"
versionCode 83
versionName "1.7.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
aaptOptions {
// Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "Materialious",
"version": "1.7.0",
"version": "1.7.1",
"description": "Modern material design for Invidious.",
"author": {
"name": "Ward Pearce",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "materialious",
"version": "1.7.0",
"version": "1.7.1",
"private": true,
"scripts": {
"dev": "vite dev",
+5 -18
View File
@@ -23,36 +23,22 @@ function fetchWithRedirects(targetUrl, options, redirectCount = 0) {
return reject(new Error('Too many redirects'));
}
let redirectHeaderLocation = res.headers.location;
// Handle relative URLs
if (redirectHeaderLocation.startsWith('/')) {
redirectHeaderLocation = targetUrl.host + redirectHeaderLocation;
}
// Add http:// if missing from the Location header
if (!redirectHeaderLocation.startsWith('http')) {
redirectHeaderLocation = 'http://' + redirectHeaderLocation;
}
try {
// Attempt to create the redirect URL
let redirectUrl = new URL(redirectHeaderLocation);
const redirectUrl = new URL(res.headers.location, targetUrl);
return resolve(fetchWithRedirects(redirectUrl, options, redirectCount + 1));
} catch (error) {
// Catch invalid URL errors
return reject(new Error(`Invalid URL in redirect: ${error.message}`));
}
}
resolve(res); // Resolve with the final response if not a redirect
});
req.on('error', reject);
req.on('error', (error) => reject(error)); // Better error handling for request
req.end();
});
}
const server = http.createServer(async (req, res) => {
setCorsHeaders(res);
@@ -66,10 +52,11 @@ const server = http.createServer(async (req, res) => {
return res.end('No URL provided to fetch.');
}
const targetUrl = req.url.slice(1); // Remove leading '/'
let targetUrl = req.url.slice(1); // Remove leading '/'
let parsedTarget;
try {
if (!targetUrl.startsWith('http')) {
// Ensure protocol (http) is added if missing
if (!targetUrl.startsWith('http://') && !targetUrl.startsWith('https://')) {
targetUrl = 'http://' + targetUrl;
}
parsedTarget = new URL(targetUrl);
+1 -1
View File
@@ -5,7 +5,7 @@ import json
import os
import re
LATEST_VERSION = "1.7.0"
LATEST_VERSION = "1.7.1"
WORKING_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "materialious")
ROOT_PACKAGE = os.path.join(WORKING_DIR, "package.json")