-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworker.js
More file actions
20 lines (19 loc) · 842 Bytes
/
Copy pathworker.js
File metadata and controls
20 lines (19 loc) · 842 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// Cloudflare Worker adapter (optional deployment target).
// wrangler.toml would set: main = "worker.js", nodejs_compat not required (fetch-only).
// Configure env vars as Worker secrets/vars: PAYMENT_MODE, PAY_TO, FACILITATOR_URL, etc.
import { handle } from './src/handler.js';
export default {
async fetch(request, env) {
const url = new URL(request.url);
const headers = {};
request.headers.forEach((v, k) => { headers[k.toLowerCase()] = v; });
const result = await handle(
{ method: request.method, path: url.pathname, query: url.searchParams, headers, resource: url.toString() },
env || {},
);
return new Response(JSON.stringify(result.body, null, 2), {
status: result.status,
headers: { 'content-type': 'application/json; charset=utf-8', ...(result.headers || {}) },
});
},
};