fixed bugs
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user