Skip to content

Commit

Permalink
Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
jason5ng32 committed Jul 15, 2024
1 parent 0c8cad2 commit 12f5c48
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 126 deletions.
4 changes: 1 addition & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,4 @@ SECURITY_BLACKLIST_LOG_FILE_PATH=""
SECURITY_RATE_LIMIT=""
SECURITY_DELAY_AFTER=""
# Google Analytics
VITE_GOOGLE_ANALYTICS_ID=""
# SpeedTest Patch
VITE_SPEEDTEST_REVERSE_URL=""
VITE_GOOGLE_ANALYTICS_ID=""
16 changes: 0 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ You can use the program without adding any environment variables, but if you wan
| `CLOUDFLARE_API` | No | `""` | API Key for Cloudflare, used to obtain AS system information through Cloudflare |
| `MAC_LOOKUP_API_KEY` | No | `""` | API Key for MAC Lookup, used to obtain MAC address information |
| `VITE_GOOGLE_ANALYTICS_ID` | **Yes** | `""` | Google Analytics ID, used to track user behavior |
| `VITE_SPEEDTEST_REVERSE_URL` | No | `""` | Reverse URL for Speedtest, temporary used for solving the CORS problem |

### Using Environment Variables in a Node Environment

Expand Down Expand Up @@ -140,21 +139,6 @@ docker run -d -p 18966:18966 \

```

## 🚀 Deploying Speed Test Reverse Proxy

This project uses the `@cloudflare/speedtest` npm package to measure internet speeds. As of 2024-07-11, the domain `speed.cloudflare.com` has implemented CORS protection, prohibiting cross-origin access, which has rendered the speed test functionality unusable.

I believe this might be a temporary configuration error on Cloudflare's part, as `@cloudflare/speedtest` is an official open-source project. Unless officially deprecated or discontinued, cross-origin access should theoretically continue to be allowed.

However, until the official fix is implemented, we can still resolve this issue by patching. Here, a Cloudflare Worker is used as a reverse proxy (theoretically this might impair the speed test results, but it remains within acceptable limits). The steps are as follows:

1. Create a new project in the Cloudflare Worker dashboard, and copy all the code from `cfworker/worker.js` in this project.
2. Modify the `allowedDomains` array in the code to include your own domain.
3. Upload and deploy the modified code to your Cloudflare Worker.
4. Retrieve the access URL of your Cloudflare Worker
5. Return to your server and set the value of the environment variable `VITE_SPEEDTEST_REVERSE_URL` to the access URL of your CF Worker.
6. Recompile the `MyIP` project and restart the service.

## 👩🏻‍💻 Advanced Usage

If you're using a proxy for internet access, consider adding this rule to your proxy configuration (modify it according to your client). This setup lets you check both your real IP and the IP when using the proxy:
Expand Down
16 changes: 0 additions & 16 deletions README_FR.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ Vous pouvez utiliser le programme sans ajouter de variables d'environnement, mai
| `CLOUDFLARE_API` | Non | `""` | Clé API pour Cloudflare, utilisée pour obtenir des informations sur le système AS via Cloudflare |
| `MAC_LOOKUP_API_KEY` | Non | `""` | Clé API pour MAC Lookup, utilisée pour obtenir des informations sur l'adresse MAC via MAC Lookup |
| `VITE_GOOGLE_ANALYTICS_ID` | **Oui** | `""` | Identifiant Google Analytics, utilisé pour l'analyse des utilisateurs |
| `VITE_SPEEDTEST_REVERSE_URL` | Non | `""` | URL inversée pour Speedtest, utilisée temporairement pour résoudre le problème CORS |

### Utilisation des variables d'environnement dans un environnement Node

Expand Down Expand Up @@ -140,21 +139,6 @@ docker run -d -p 18966:18966 \

```

## 🚀 Déploiement du proxy inverse de test de vitesse

Ce projet utilise le package npm `@cloudflare/speedtest` pour mesurer les vitesses Internet. Depuis le 11-07-2024, le domaine `speed.cloudflare.com` a mis en place une protection CORS, interdisant les accès inter-domaines, ce qui a rendu la fonctionnalité de test de vitesse inutilisable.

Je pense qu'il s'agit peut-être d'une erreur de configuration temporaire de la part de Cloudflare, car `@cloudflare/speedtest` est un projet open-source officiel. À moins que l'officiel ne le déclare obsolète ou ne cesse de le maintenir, l'accès inter-domaines devrait théoriquement continuer à être autorisé.

Cependant, avant que la correction officielle ne soit appliquée, nous pouvons toujours résoudre ce problème en appliquant un correctif. Ici, un Worker Cloudflare est utilisé comme proxy inverse (théoriquement cela pourrait nuire aux résultats du test de vitesse, mais reste dans des limites acceptables). Les étapes sont les suivantes :

1. Créez un nouveau projet dans le tableau de bord du Worker Cloudflare et copiez tout le code de `cfworker/worker.js` de ce projet.
2. Modifiez le tableau `allowedDomains` dans le code pour inclure votre propre domaine.
3. Téléchargez et déployez le code modifié sur votre Worker Cloudflare.
4. Récupérez l'URL d'accès de votre Worker Cloudflare.
5. Retournez sur votre serveur et configurez l'URL d'accès de votre Worker CF comme valeur pour la variable d'environnement `VITE_SPEEDTEST_REVERSE_URL`.
6. Recompilez le projet `MyIP` et redémarrez le service.

## 👩🏻‍💻 Utilisation avancée

Si vous utilisez un proxy pour accéder à Internet, envisagez d'ajouter cette règle à votre configuration de proxy (modifiez-la en fonction de votre client). Cette configuration vous permet de vérifier à la fois votre véritable adresse IP et l'adresse IP lorsque vous utilisez le proxy :
Expand Down
16 changes: 0 additions & 16 deletions README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ docker run -d -p 18966:18966 --name myip --restart always jason5ng32/myip:latest
| `CLOUDFLARE_API` || `""` | Cloudflare 的 API Key,用于通过 Cloudflare 获取 AS 系统的信息 |
| `MAC_LOOKUP_API_KEY` || `""` | MAC 查询的 API Key,用于通过 MAC Lookup 获取 MAC 地址的归属信息 |
| `VITE_GOOGLE_ANALYTICS_ID` | **** | `""` | Google Analytics 的 ID,用于统计访问量 |
| `VITE_SPEEDTEST_REVERSE_URL` || `""` | Speedtest 的反向代理地址,用于临时解决 Cloudflare 近期出现的 CORS 问题 |

### 在 Node 环境里使用环境变量

Expand Down Expand Up @@ -142,21 +141,6 @@ docker run -d -p 18966:18966 \

```

## 🚀 部署网速测试反向代理

本项目使用了 `@cloudflare/speedtest` 这个 npm 包进行网速测速,大约在 2024-07-11 开始,`speed.cloudflare.com` 这个域名开启了 CORS 保护,不允许跨域访问,这导致网速测试功能无法使用。

我相信这可能是 Cloudflare 的一个临时设置错误,因为 `@cloudflare/speedtest` 是一个官方的开源项目,除非官方明确下架或不再维护,否则理论上应当继续允许跨域访问。

然而,在官方修复这个问题之前,我们依然可以通过打补丁的方式来解决这个问题。这里需要使用 Cloudflare Worker 作为反向代理进行解决(理论上这会让测速效果有所损耗,但因为都是 Cloudflare 的服务器,损耗会在接受的范围)。操作方法如下:

1. 前往 Cloudflare Worker 后台创建一个新项目,并复制本项目 `cfworker/worker.js` 里所有的代码
2. 修改代码里 `allowedDomains` 数组里的域名为你自己的域名
3. 将修改后的代码上传并部署到 Cloudflare Worker
4. 获取你的 Cloudflare Worker 的访问 URL
5. 回到你的服务端,将 CF Worker 的访问 URL 作为环境变量 `VITE_SPEEDTEST_REVERSE_URL` 的值进行配置
6. 重新编译 `MyIP` 项目并重启服务

## 👩🏻‍💻 高级用法

如果你在通过代理上网,可以考虑在你的代理配置里,增加下面的规则(请根据你使用的客户端进行修改),这样就可以实现同时查询真实 IP 和代理后的 IP:
Expand Down
55 changes: 0 additions & 55 deletions cfworker/worker.js

This file was deleted.

3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"version": "3.0.0",
"type": "module",
"scripts": {
"postinstall": "patch-package",
"dev": "concurrently \"vite\" \"nodemon backend-server.js\"",
"build": "vite build",
"preview": "vite preview",
Expand All @@ -29,9 +28,7 @@
"flag-icons": "^7.2.3",
"http-proxy-middleware": "^3.0.0",
"nodemon": "^3.1.4",
"patch-package": "^8.0.0",
"pinia": "^2.1.7",
"postinstall": "^0.10.3",
"svgmap": "^2.10.1",
"vue": "^3.4.31",
"vue-i18n": "^9.13.1",
Expand Down
17 changes: 0 additions & 17 deletions patches/@cloudflare+speedtest+1.3.0.patch

This file was deleted.

0 comments on commit 12f5c48

Please sign in to comment.