// Main request handler
export default {
async fetch(request, env) {
const url = new URL(request.url);
const secretKey = env.SECRET_KEY; // Defined in the Cloudflare Workers environment
const apiKey = env.API_KEY; // Defined in the Cloudflare Workers environment
// CORS check for allowed domains
//if (!checkCors(url.origin)) {
// return new Response('CORS check failed', { status: 403 });
//}
// Handle /v1/signature path
if (url.pathname === '/v1/signature') {
const nonce = generateNonce();
const signature = await generateHMAC(nonce, apiKey, secretKey);
return new Response(
JSON.stringify({
apiKey,
signature,
nonce,
})
//,
//{
// headers: {
// 'Content-Type': 'application/json',
// 'Access-Control-Allow-Origin': "https://connect-example-react.metalpay.com",
// 'Access-Control-Allow-Methods': 'GET, OPTIONS',
// }
//}
);
}
return env.ASSETS.fetch(request);
},
}
// Main request handler
export default {
async fetch(request, env) {
const url = new URL(request.url);
const secretKey = env.SECRET_KEY; // Defined in the Cloudflare Workers environment
const apiKey = env.API_KEY; // Defined in the Cloudflare Workers environment
// CORS check for allowed domains
//if (!checkCors(url.origin)) {
// return new Response('CORS check failed', { status: 403 });
//}
// Handle /v1/signature path
if (url.pathname === '/v1/signature') {
const nonce = generateNonce();
const signature = await generateHMAC(nonce, apiKey, secretKey);
return new Response(
JSON.stringify({
apiKey,
signature,
nonce,
})
//,
//{
// headers: {
// 'Content-Type': 'application/json',
// 'Access-Control-Allow-Origin': "https://connect-example-react.metalpay.com",
// 'Access-Control-Allow-Methods': 'GET, OPTIONS',
// }
//}
);
}
return env.ASSETS.fetch(request);
},
}