added comments
This commit is contained in:
@@ -38,8 +38,8 @@ 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
|
||||
/// Browsers send OPTIONS request sometimes to check webserver's allowed headers and methods.
|
||||
/// My C# backend doesn't support OPTIONS, so the proxy answer to OPTIONS request that all headers and methods are allowed.
|
||||
export async function responseToOPTIONS(req: NextRequest): Promise<NextResponse> {
|
||||
// console.log('proxy responding to CORS OPTIONS', req.url)
|
||||
|
||||
@@ -48,8 +48,8 @@ export async function responseToOPTIONS(req: NextRequest): Promise<NextResponse>
|
||||
headers: {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'GET, POST, PUT, PATCH, DELETE, HEAD',
|
||||
'Access-Control-Allow-Headers':
|
||||
req.headers.get('access-control-request-headers') || 'Content-Type, Authorization',
|
||||
'Access-Control-Allow-Headers': '*',
|
||||
// req.headers.get('access-control-request-headers') || 'Content-Type, Authorization'
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// Directories in src/api/proxy/ are routes.
|
||||
// Their paths are stored here to simplify refactoring.
|
||||
export const PROXY_PATHS = {
|
||||
saveParserBackend: '/api/proxy/saveParserBackend',
|
||||
}
|
||||
|
||||
@@ -4,10 +4,12 @@ import { redirectRequest, responseToOPTIONS as respondToOPTIONS } from '@/app/ap
|
||||
import { PROXY_PATHS } from '@/app/api/proxy/paths'
|
||||
import { appConfig } from '@/lib/configLoader'
|
||||
|
||||
// Forwards the incoming request to the save parser backend.
|
||||
async function redirect(req: NextRequest): Promise<NextResponse> {
|
||||
return await redirectRequest(req, PROXY_PATHS.saveParserBackend, appConfig.services.saveParserBackend.url)
|
||||
}
|
||||
|
||||
// handlers for each request method on this route
|
||||
export const GET = redirect
|
||||
export const POST = redirect
|
||||
export const PUT = redirect
|
||||
|
||||
Reference in New Issue
Block a user