format: file width decreased from 120 to 80
This commit is contained in:
@@ -18,7 +18,8 @@ export async function redirectRequest(
|
||||
|
||||
// Replace '/api/proxy/parserBackend' with backend URL, preserve everything after
|
||||
// e.g. '/api/proxy/extra/path?id=123' -> 'http://backend-server/extra/path?id=123'
|
||||
const backendUrl = backendBaseUrl + reqUrl.substring(proxyIndex + proxyUrl.length)
|
||||
const backendUrl =
|
||||
backendBaseUrl + reqUrl.substring(proxyIndex + proxyUrl.length)
|
||||
// console.log('redirecting', req.url, 'to', backendUrl)
|
||||
|
||||
const backendRes = await fetch(backendUrl, {
|
||||
@@ -33,21 +34,26 @@ export async function redirectRequest(
|
||||
status: backendRes.status,
|
||||
headers: {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Content-Type': backendRes.headers.get('content-type') || 'application/octet-stream',
|
||||
'Content-Type':
|
||||
backendRes.headers.get('content-type') ||
|
||||
'application/octet-stream',
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/// 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> {
|
||||
export async function responseToOPTIONS(
|
||||
req: NextRequest
|
||||
): Promise<NextResponse> {
|
||||
// console.log('proxy responding to CORS OPTIONS', req.url)
|
||||
|
||||
return new NextResponse(null, {
|
||||
status: 200,
|
||||
headers: {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'GET, POST, PUT, PATCH, DELETE, HEAD',
|
||||
'Access-Control-Allow-Methods':
|
||||
'GET, POST, PUT, PATCH, DELETE, HEAD',
|
||||
'Access-Control-Allow-Headers': '*',
|
||||
// req.headers.get('access-control-request-headers') || 'Content-Type, Authorization'
|
||||
},
|
||||
|
||||
@@ -1,12 +1,19 @@
|
||||
import type { NextRequest } from 'next/server'
|
||||
import { NextResponse } from 'next/server'
|
||||
import { redirectRequest, responseToOPTIONS as respondToOPTIONS } from '@/app/api/proxy/functions'
|
||||
import {
|
||||
redirectRequest,
|
||||
responseToOPTIONS as respondToOPTIONS,
|
||||
} from '@/app/api/proxy/functions'
|
||||
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)
|
||||
return await redirectRequest(
|
||||
req,
|
||||
PROXY_PATHS.saveParserBackend,
|
||||
appConfig.services.saveParserBackend.url
|
||||
)
|
||||
}
|
||||
|
||||
// handlers for each request method on this route
|
||||
|
||||
Reference in New Issue
Block a user