fixed bugs

This commit is contained in:
Altair-sh
2025-05-23 01:51:50 +05:00
parent 8e4ce66cc4
commit 8c270fc4ea
14 changed files with 85 additions and 47 deletions
@@ -8,7 +8,7 @@ export async function redirectRequest(
proxyUrl: string,
backendBaseUrl: string
): Promise<NextResponse> {
const reqUrl = req.url // full URL e.g. http://localhost:3000/api/proxy?id=123&foo=bar
const reqUrl = req.url // full URL e.g. http://localhost:3000/api/proxy?id=123
// Find position of proxyPath in reqUrl
const proxyIndex = reqUrl.indexOf(proxyUrl)
@@ -17,9 +17,9 @@ export async function redirectRequest(
}
// Replace '/api/proxy/parserBackend' with backend URL, preserve everything after
// e.g. '/api/proxy/extra/path?id=123' -> 'http://your-backend-server/extra/path?id=123'
// e.g. '/api/proxy/extra/path?id=123' -> 'http://backend-server/extra/path?id=123'
const backendUrl = backendBaseUrl + reqUrl.substring(proxyIndex + proxyUrl.length)
console.log('redirecting', req.url, 'to', backendUrl)
// console.log('redirecting', req.url, 'to', backendUrl)
const backendRes = await fetch(backendUrl, {
method: req.method,
@@ -41,7 +41,7 @@ export async function redirectRequest(
/// Browsers send OPTIONS request sometimes to check webserver allowed headers and methods.
/// My backend doesn't support such requests so use proxy to answer to it that all headers and methods are allowed
export async function responseToOPTIONS(req: NextRequest): Promise<NextResponse> {
console.log('proxy responding to CORS OPTIONS', req.url)
// console.log('proxy responding to CORS OPTIONS', req.url)
return new NextResponse(null, {
status: 200,
@@ -1,8 +1,8 @@
import type { NextRequest } from 'next/server'
import { NextResponse } from 'next/server'
import { redirectRequest, responseToOPTIONS as respondToOPTIONS } from '@/app/api/proxy/proxyFunctions'
import { appConfig } from '@/app/lib/configLoader'
import { PROXY_PATHS } from '../../paths'
import { redirectRequest, responseToOPTIONS as respondToOPTIONS } from '@/app/api/proxy/functions'
import { PROXY_PATHS } from '@/app/api/proxy/paths'
import { appConfig } from '@/lib/configLoader'
async function redirect(req: NextRequest): Promise<NextResponse> {
return await redirectRequest(req, PROXY_PATHS.saveParserBackend, appConfig.services.saveParserBackend.url)