Advertisement
MatiGe

Untitled

May 26th, 2025
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. // netlify/functions/verifyCode.js
  2.  
  3. // ... (your database access logic) ...
  4. // const STUB_DATABASE_CODES = ["123456", "789012", "112233"]; // Example
  5.  
  6. exports.handler = async function (event, context) {
  7. const codeToVerify = event.queryStringParameters.code;
  8. let isValid = false;
  9.  
  10. // --- Your logic to check the code ---
  11. if (codeToVerify) {
  12. // Example: isValid = STUB_DATABASE_CODES.includes(codeToVerify);
  13. // Replace this with your actual database check
  14. isValid = (codeToVerify === "123456" || codeToVerify === "789012"); // Placeholder
  15. }
  16. // --- End of your logic ---
  17.  
  18. // --- PREFLIGHT OPTIONS REQUEST HANDLING ---
  19. // Browsers may send an OPTIONS request first for certain cross-origin requests
  20. if (event.httpMethod === 'OPTIONS') {
  21. return {
  22. statusCode: 200, // Or 204 No Content
  23. headers: {
  24. "Access-Control-Allow-Origin": "https://matias56.itch.io", // Or "*" for testing
  25. "Access-Control-Allow-Methods": "GET, OPTIONS", // Methods your function supports
  26. "Access-Control-Allow-Headers": "Content-Type" // Headers your client might send
  27. },
  28. body: '' // Optional
  29. };
  30. }
  31.  
  32. // --- ACTUAL GET REQUEST HANDLING ---
  33. return {
  34. statusCode: 200,
  35. headers: {
  36. "Content-Type": "application/json",
  37. // Option 1: Allow any origin (less secure, okay for initial testing)
  38. // "Access-Control-Allow-Origin": "*",
  39.  
  40. // Option 2: Allow only your itch.io game's origin (RECOMMENDED for production)
  41. // Replace 'YOUR-USERNAME.itch.io' with your actual itch.io domain
  42. "Access-Control-Allow-Origin": "https://matias56.itch.io",
  43.  
  44. // These might also be useful depending on the complexity of your requests
  45. "Access-Control-Allow-Methods": "GET, OPTIONS",
  46. "Access-Control-Allow-Headers": "Content-Type" // If Unity sends Content-Type or other custom headers
  47. },
  48. body: JSON.stringify({ isValid: isValid })
  49. };
  50. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement