Skip to content

Add fsnebula.org and api mirrors - #429

Open
Shivansps wants to merge 2 commits into
KnossosNET:mainfrom
Shivansps:repo-and-api-mirrors
Open

Add fsnebula.org and api mirrors#429
Shivansps wants to merge 2 commits into
KnossosNET:mainfrom
Shivansps:repo-and-api-mirrors

Conversation

@Shivansps

@Shivansps Shivansps commented Aug 1, 2026

Copy link
Copy Markdown
Member

This should make knossos to try diferent mirror in case knossos cant not connect to the main one at startup.

fsnebula.space uses a cloudflare worker to redirect trafic, for the record ill leave the cloudflare worker the code here.

export default {
  async fetch(request) {
    const url = new URL(request.url);

    // Rute by path -> host real
    let origin;
    if (url.pathname.startsWith("/api/"))          origin = "https://api.fsnebula.org";
    else if (url.pathname.startsWith("/storage/")) origin = "https://dl.fsnebula.org";
    else                                           origin = "https://fsnebula.org";

    const target = origin + url.pathname + url.search;

    const req = new Request(target, {
      method: request.method,
      headers: request.headers,
      body: ["GET", "HEAD"].includes(request.method) ? undefined : request.body,
      redirect: "follow",
    });
    req.headers.delete("Host"); 

    const noCache = url.pathname.endsWith("repo_minimal.json") || url.pathname.startsWith("/api/");

    const resp = await fetch(req, noCache ? { cf: { cacheEverything: false, cacheTtl: 0 } } : undefined);

    const out = new Response(resp.body, resp);        // stream
    out.headers.set("Access-Control-Allow-Origin", "*");
    if (noCache) out.headers.set("Cache-Control", "no-store");
    return out;
  }
};

@Shivansps Shivansps added the enhancement New feature or request label Aug 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant