@@ -11,7 +11,14 @@ const parsePerMinuteLimit = (raw: string | undefined, fallback: number): number
1111} ;
1212
1313export const onRequest : PagesFunction < Env > = async ( { request, env } ) => {
14- if ( request . method !== "GET" && request . method !== "HEAD" ) {
14+ const url = new URL ( request . url ) ;
15+ const upstreamPath = url . pathname . replace ( / ^ \/ v e 2 d b e / , "" ) ;
16+ const isTileListEndpoint = upstreamPath === "/geodata/gettile.asp" ;
17+ const allowsPost = isTileListEndpoint ;
18+ const methodAllowed =
19+ request . method === "GET" || request . method === "HEAD" || ( allowsPost && request . method === "POST" ) ;
20+
21+ if ( ! methodAllowed ) {
1522 return new Response ( "Method not allowed" , { status : 405 } ) ;
1623 }
1724
@@ -29,15 +36,17 @@ export const onRequest: PagesFunction<Env> = async ({ request, env }) => {
2936 } ) ;
3037 }
3138
32- const url = new URL ( request . url ) ;
33- const upstreamPath = url . pathname . replace ( / ^ \/ v e 2 d b e / , "" ) ;
3439 const upstream = new URL ( `https://www.ve2dbe.com${ upstreamPath } ${ url . search } ` ) ;
40+ const contentType = request . headers . get ( "content-type" ) ;
41+ const shouldForwardBody = request . method === "POST" || request . method === "PUT" || request . method === "PATCH" ;
3542
3643 const response = await fetch ( upstream . toString ( ) , {
3744 method : request . method ,
3845 headers : {
3946 accept : request . headers . get ( "accept" ) ?? "*/*" ,
47+ ...( contentType ? { "content-type" : contentType } : { } ) ,
4048 } ,
49+ body : shouldForwardBody ? request . body : undefined ,
4150 } ) ;
4251
4352 return new Response ( response . body , {
0 commit comments