Static files
export default {
async fetch(request) {
const url = new URL(request.url);
// Construct the GitHub raw URL
const githubUrl = url.pathname === '/'
? 'https://raw.githubusercontent.com/Vija02/theopenpresenter-static/refs/heads/main'
: `https://raw.githubusercontent.com/Vija02/theopenpresenter-static/refs/heads/main${url.pathname}`;
// Fetch from GitHub
const response = await fetch(githubUrl, {
cf: {
// Cache in Cloudflare's CDN for 1 year
cacheTtl: 31536000,
cacheEverything: true,
}
});
// Clone the response and add CORS headers
const newResponse = new Response(response.body, response);
newResponse.headers.set('Access-Control-Allow-Origin', '*');
newResponse.headers.set('Cache-Control', 'public, max-age=31536000, immutable');
return newResponse;
}
};Configuration
Last updated