Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // netlify/functions/verifyCode.js
- // ... (your database access logic) ...
- // const STUB_DATABASE_CODES = ["123456", "789012", "112233"]; // Example
- exports.handler = async function (event, context) {
- const codeToVerify = event.queryStringParameters.code;
- let isValid = false;
- // --- Your logic to check the code ---
- if (codeToVerify) {
- // Example: isValid = STUB_DATABASE_CODES.includes(codeToVerify);
- // Replace this with your actual database check
- isValid = (codeToVerify === "123456" || codeToVerify === "789012"); // Placeholder
- }
- // --- End of your logic ---
- // --- PREFLIGHT OPTIONS REQUEST HANDLING ---
- // Browsers may send an OPTIONS request first for certain cross-origin requests
- if (event.httpMethod === 'OPTIONS') {
- return {
- statusCode: 200, // Or 204 No Content
- headers: {
- "Access-Control-Allow-Origin": "https://matias56.itch.io", // Or "*" for testing
- "Access-Control-Allow-Methods": "GET, OPTIONS", // Methods your function supports
- "Access-Control-Allow-Headers": "Content-Type" // Headers your client might send
- },
- body: '' // Optional
- };
- }
- // --- ACTUAL GET REQUEST HANDLING ---
- return {
- statusCode: 200,
- headers: {
- "Content-Type": "application/json",
- // Option 1: Allow any origin (less secure, okay for initial testing)
- // "Access-Control-Allow-Origin": "*",
- // Option 2: Allow only your itch.io game's origin (RECOMMENDED for production)
- // Replace 'YOUR-USERNAME.itch.io' with your actual itch.io domain
- "Access-Control-Allow-Origin": "https://matias56.itch.io",
- // These might also be useful depending on the complexity of your requests
- "Access-Control-Allow-Methods": "GET, OPTIONS",
- "Access-Control-Allow-Headers": "Content-Type" // If Unity sends Content-Type or other custom headers
- },
- body: JSON.stringify({ isValid: isValid })
- };
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement