nornagon / cdda-guide

The Hitchhiker's Guide to the Cataclysm
https://cdda-guide.nornagon.net
GNU General Public License v3.0
113 stars 26 forks source link

Add Dockerfile | 增加 Dockerfile #166

Closed DoiiarX closed 7 months ago

DoiiarX commented 9 months ago

Add Dockerfile | 增加 Dockerfile

This addition addresses the issue mentioned here.

这个添加解决的问题在这里.


Issue with raw.githubusercontent.com Access | raw.githubusercontent.com 访问问题

Another part of the issue relates to the inability to directly connect to raw.githubusercontent.com.

The solution is provided in the following commit: Reproxy.

问题的另一部分,与无法直接连接到 raw.githubusercontent.com 有关。

解决方案提供在以下提交中:重新配置代理

When unable to access raw.githubusercontent.com directly, you can configure a Worker on Cloudflare to circumvent network restrictions using Cloudflare's IP pool.

当无法直接访问 raw.githubusercontent.com 时,您可以在 Cloudflare 上配置一个 Worker,利用 Cloudflare 的 IP 池来规避网络屏蔽。

Code for Handling raw.githubusercontent.com Access by Cloudflare Worker | 用 Cloudflare Worker 处理 raw.githubusercontent.com 访问问题的代码

addEventListener('fetch', event => {
  event.respondWith(handleRequest(event.request))
})

async function handleRequest(request) {
  const url = new URL(request.url);
  const headers_Origin = request.headers.get("Access-Control-Allow-Origin") || "*"

  // Check if the requested URL matches one of the specific paths
  if (!url.pathname.startsWith('/nornagon/cdda-guide/') && !url.pathname.startsWith('/CleverRaven/Cataclysm-DDA/') && !url.pathname.startsWith('/nornagon/cdda-data/')) {
    // If not, return a 403 Forbidden error
    return new Response('Access denied: Not an allowed route.', { status: 403 });
  }

  url.host = 'raw.githubusercontent.com';
  const modifiedRequest = new Request(url.toString(), {
    headers: request.headers,
    method: request.method,
    body: request.body,
    redirect: 'follow'
  });

  const response = await fetch(modifiedRequest);
  const modifiedResponse = new Response(response.body, response);

  // Add the response header to allow cross-origin access
  modifiedResponse.headers.set('Access-Control-Allow-Origin', headers_Origin);

  return modifiedResponse;
}

Mirror site | 镜像站

Accessible cdda-guide mirror site in China: https://cdda.doiiars.com/?lang=zh_CN 中国可以访问的cdda-guide镜像站:https://cdda.doiiars.com/?lang=zh_CN

nornagon commented 7 months ago

Thanks for the suggestion, but for the reasons already outlined in that issue, I don't feel a Dockerfile is useful for this project. The issue with raw.githubusercontent.com not being accessible in China is unfortunate but isn't addressed by this PR. The cloudflare worker solution is indeed correct, but unfortunately is not free, so it would make HHG infinitely more expensive to operate :)