ctucx.git: trainsearch

web based trip-planner, fork of https://cyberchaos.dev/yuka/trainsearch

commit 31cc0fc3c02292e5a6fd946f775e553434474eae
parent c2df8eef1d1e7f169c807437f6b80cbef05b7070
Author: Katja (ctucx) <git@ctu.cx>
Date: Wed, 29 Jan 2025 15:04:11 +0100

general: refactor proxy url-handling
3 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/src/reihung/DB/index.js b/src/reihung/DB/index.js
@@ -18,7 +18,7 @@ export const getDBCoachSequenceUrl = (category, number, evaNumber, date) => {
   searchParams.append("time", formatISO(date));
   searchParams.append("evaNumber", evaNumber);
   searchParams.append("number", number);
-  return `/https://www.bahn.de/web/api/reisebegleitung/wagenreihung/vehicle-sequence?${searchParams}`;
+  return `/db/vehicle-sequence?${searchParams}`;
 };
 
 async function coachSequence(category, number, evaNumber, date) {
diff --git a/src/shim/cross-fetch.js b/src/shim/cross-fetch.js
@@ -4,6 +4,27 @@ export const fetch = (resource, options) => {
 	if (!(resource instanceof Request)) {
 		resource = new Request(resource);
 	}
-	resource = new Request("/"+resource.url, resource);
+
+
+	const replacement = {
+		'https://app.vendo.noncd.db.de/mob/location/search':       '/db/vendo/locations',
+		'https://app.vendo.noncd.db.de/mob/angebote/fahrplan':     '/db/vendo/journeys',
+		'https://app.vendo.noncd.db.de/mob/angebote/recon':        '/db/vendo/journey',
+		'https://app.vendo.noncd.db.de/mob/bahnhofstafel/abfahrt': '/db/vendo/departures',
+		'https://nah.sh.hafas.de/bin/mgate.exe?':                  '/hafas/nahsh',
+		'https://www.rmv.de/auskunft/bin/jp/mgate.exe?':           '/hafas/rmv',
+		'https://vrn.hafas.de/bin/mgate.exe?':                     '/hafas/vrn',
+		'https://bvg-apps-ext.hafas.de/bin/mgate.exe?':            '/hafas/bvg',
+		'https://fahrplan.oebb.at/bin/mgate.exe?':                 '/hafas/oebb',
+	};
+
+	let url = replacement[resource.url];
+
+	if (url === undefined) {
+		url = resource.url.replace('https://app.vendo.noncd.db.de/mob/location/details', '/db/vendo/location');
+		url = url.replace('https://app.vendo.noncd.db.de/mob/zuglauf',                   '/db/vendo/trip');
+	}
+
+	resource = new Request(url, resource);
 	return globalThis.fetch(resource, options);
 }
diff --git a/webpack.config.js b/webpack.config.js
@@ -48,8 +48,8 @@ export default {
 			progress: true,
 		},
 		proxy: [{
-			context: [ '/db', '/https:' ],
-			target: 'https://oeffi.ctu.cx',
+			context: [ '/hafas', '/db' ],
+			target: 'https://oeffi.katja.wtf',
 			changeOrigin: true,
 		}],
 	},