export default {
async fetch(
request: Request,
env: Env,
ctx: ExecutionContext,
): Promise<Response> {
if (request.method !== "POST") {
return new Response(null, {
status: 405,
statusText: "Method Not Allowed",
});
}
const userAgent = request.headers.get("user-agent");
const data = await request.json();
const connectionString = env.staging.connectionString;
console.log(userAgent, data, connectionString);
if (userAgent?.includes("<example>")) {
console.log("correct agent")
const sql = postgres(connectionString, { prepare: false });
ctx.waitUntil(sql`INSERT INTO payment_logs(user_id) VALUES (999);`);
return new Response(undefined, { status: 200 });
}
return new Response(undefined, { status: 405 });
},
};
export default {
async fetch(
request: Request,
env: Env,
ctx: ExecutionContext,
): Promise<Response> {
if (request.method !== "POST") {
return new Response(null, {
status: 405,
statusText: "Method Not Allowed",
});
}
const userAgent = request.headers.get("user-agent");
const data = await request.json();
const connectionString = env.staging.connectionString;
console.log(userAgent, data, connectionString);
if (userAgent?.includes("<example>")) {
console.log("correct agent")
const sql = postgres(connectionString, { prepare: false });
ctx.waitUntil(sql`INSERT INTO payment_logs(user_id) VALUES (999);`);
return new Response(undefined, { status: 200 });
}
return new Response(undefined, { status: 405 });
},
};