-
-
Save cferdinandi/180a8580e8ba075e20262f7cc2183f9a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Define response headers | |
let headers = new Headers({ | |
'Access-Control-Allow-Origin': '*', | |
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS, HEAD', | |
'Access-Control-Allow-Headers': '*' | |
}); | |
/** | |
* Respond to the request | |
* @param {Request} request | |
*/ | |
async function handleRequest(request) { | |
// Catchall response | |
return new Response(JSON.stringify(['Hello, world!']), { | |
status: 200, | |
headers: headers | |
}); | |
} | |
// Listen for API calls | |
addEventListener('fetch', function (event) { | |
event.respondWith(handleRequest(event.request)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment