Static files

Some plugins may require us to serve many different media files. Rather than storing these in the main repo, they are stored in https://github.com/Vija02/theopenpresenter-static/

One way to access these files is directly through the github URL

However, to prevent CORS/ORB issue, it is recommended that you serve this file from a domain you control. There are many ways to do this like deploying a static server or proxying github.

Here is an example on how to handle this through a Cloudflare Worker:

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

By default, we will directly use the github link to access the files. To override this, define a new path in the STATIC_FILES_PATH environment variable.

Last updated