Skip to content

Commit 0f00a7c

Browse files
committed
Fix ve2dbe SRTM tile list POST handling
1 parent 4a0936d commit 0f00a7c

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

functions/ve2dbe/[[path]].ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@ const parsePerMinuteLimit = (raw: string | undefined, fallback: number): number
1111
};
1212

1313
export 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(/^\/ve2dbe/, "");
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(/^\/ve2dbe/, "");
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

Comments
 (0)