23 lines
553 B
TypeScript
23 lines
553 B
TypeScript
import curlResponse from "../src/curl-response.ts";
|
|
|
|
interface PagesContext {
|
|
request: Request;
|
|
next(): Promise<Response>;
|
|
}
|
|
|
|
export function onRequest(context: PagesContext): Response | Promise<Response> {
|
|
const { request } = context;
|
|
const userAgent = request.headers.get("user-agent") ?? "";
|
|
const pathname = new URL(request.url).pathname;
|
|
|
|
if (
|
|
request.method === "GET" &&
|
|
pathname === "/" &&
|
|
/^curl(?:\/|$)/i.test(userAgent)
|
|
) {
|
|
return curlResponse();
|
|
}
|
|
|
|
return context.next();
|
|
}
|