From d26ae957614e25880e2b04523068416d466bc3de Mon Sep 17 00:00:00 2001 From: jason5ng32 Date: Mon, 13 Jul 2026 21:06:48 +0800 Subject: [PATCH] Improvements --- AGENTS.md | 2 +- Dockerfile | 2 ++ README.md | 8 ++++---- README_FR.md | 8 ++++---- README_TR.md | 8 ++++---- README_ZH.md | 8 ++++---- 6 files changed, 19 insertions(+), 17 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 0d64ff78..69d01ee5 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -94,7 +94,7 @@ use npm / yarn — they'd produce a competing lockfile. - **Always the shared logger** (`common/logger.js`) in backend files; bare `console.*` is banned there (frontend keeps using `console.*`). - Pino first-arg-is-context: `logger.error({ err, ip }, 'short message')`. -- Env knobs: `LOG_LEVEL` (default warn), `LOG_FORMAT=json` for shippers, +- Env knobs: `LOG_LEVEL` (default info), `LOG_FORMAT=json` for shippers, `LOG_HTTP=true` to mount `pino-http` on `/api` (off by default; handlers never log "received request" lines themselves). No `NODE_ENV` anywhere. - Startup-only lines lead with an emoji (🚀 listening · 📦 ready · diff --git a/Dockerfile b/Dockerfile index 7a031a43..8fa82a6a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,6 +22,8 @@ COPY --from=build-stage /app/package.json ./ COPY --from=build-stage /app/dist ./dist COPY --from=build-stage /app/backend-server.js ./ COPY --from=build-stage /app/frontend-server.js ./ +# npm start boots the backend with `--import ./sentry-instrument.js` +COPY --from=build-stage /app/sentry-instrument.js ./ COPY --from=build-stage /app/api ./api COPY --from=build-stage /app/common ./common diff --git a/README.md b/README.md index b938acef..16d1cea2 100644 --- a/README.md +++ b/README.md @@ -133,7 +133,7 @@ Download `GeoLite2-City.mmdb` and `GeoLite2-ASN.mmdb` from your MaxMind account | `FRONTEND_PORT` | No | `"18966"` | The running port of the frontend part of the program | | `SECURITY_RATE_LIMIT` | No | `"0"` | Controls the number of requests an IP can make to the backend server every 60 minutes (set to 0 for no limit) | | `SECURITY_DELAY_AFTER` | No | `"0"` | Controls the first X requests from an IP every 20 minutes that are not subject to speed limits, and after X requests, the delay will increase | -| `SECURITY_BLACKLIST_LOG_FILE_PATH` | No | `"logs/blacklist-ip.log"` | Path setting. Records the list of IPs that triggered the limit after SECURITY_RATE_LIMIT is enabled | +| `SECURITY_BLACKLIST_LOG_FILE_PATH` | No | `""` | Opt-in on-disk ledger of rate-limited IPs (e.g. `"logs/blacklist-ip.log"`). Empty = no file is written; the event is always logged via the shared logger either way | | `LOG_LEVEL` | No | `"info"` | Minimum log level (`debug` / `info` / `warn` / `error`). Lower-level messages are suppressed. | | `LOG_FORMAT` | No | pretty | Set to `"json"` to emit one JSON event per line (for log aggregators / jq). Any other value (or unset) keeps the colored pretty output used in dev and pm2 log tails. | | `LOG_HTTP` | No | `"false"` | Set to `"true"` to enable per-request HTTP logging on `/api/*` (method, URL, status, response time). Off by default to keep pm2 logs lean. Handler-level 4xx/5xx errors are always logged regardless of this flag. | @@ -236,8 +236,8 @@ Thanks to AI, it has given me, an unemployed product manager, a rapid opportunit As a open source project, I'm very grateful to the following sponsors for their support: - + -Cloudflare Project Alexandria +Cloudflare Project Alexandria -Sentry +Sentry diff --git a/README_FR.md b/README_FR.md index 82068da5..323fc646 100644 --- a/README_FR.md +++ b/README_FR.md @@ -133,7 +133,7 @@ Téléchargez `GeoLite2-City.mmdb` et `GeoLite2-ASN.mmdb` depuis votre compte Ma | `FRONTEND_PORT` | Non | `"18966"` | Le port d'exécution de la partie frontend du programme | | `SECURITY_RATE_LIMIT` | Non | `"0"` | Contrôle le nombre de requêtes qu'une adresse IP peut faire au serveur backend toutes les 60 minutes (réglé sur 0 pour aucune limite) | | `SECURITY_DELAY_AFTER` | Non | `"0"` | Contrôle les premières X requêtes d'une adresse IP toutes les 20 minutes qui ne sont pas soumises à des limites de vitesse, et après X requêtes, le délai augmentera | -| `SECURITY_BLACKLIST_LOG_FILE_PATH` | Non | `"logs/blacklist-ip.log"` | Paramètre de chemin. Enregistre la liste des adresses IP qui ont déclenché la limite après que `SECURITY_RATE_LIMIT` soit activé | +| `SECURITY_BLACKLIST_LOG_FILE_PATH` | Non | `""` | Registre local optionnel des IP limitées (ex. `"logs/blacklist-ip.log"`). Vide = aucun fichier n'est écrit ; l'événement est de toute façon toujours journalisé via le logger partagé | | `LOG_LEVEL` | Non | `"info"` | Niveau minimum des journaux (`debug` / `info` / `warn` / `error`). Les messages de niveau inférieur sont supprimés. | | `LOG_FORMAT` | Non | pretty | Définir sur `"json"` pour émettre un événement JSON par ligne (agrégateurs de logs / jq). Toute autre valeur (ou non défini) conserve la sortie colorée lisible utilisée en dev et lors du tail des logs pm2. | | `LOG_HTTP` | Non | `"false"` | Définir sur `"true"` pour activer la journalisation par requête HTTP sur `/api/*` (méthode, URL, statut, temps de réponse). Désactivé par défaut pour garder les logs pm2 légers. Les erreurs 4xx/5xx côté handler sont toujours loguées, que ce drapeau soit activé ou non. | @@ -236,8 +236,8 @@ Merci à l'IA, qui m'a donné, à moi, un chef de produit au chômage, une oppor En tant que projet open source, je suis très reconnaissant aux sponsors suivants pour leur soutien : - + -Cloudflare Project Alexandria +Cloudflare Project Alexandria -Sentry +Sentry diff --git a/README_TR.md b/README_TR.md index 838dc013..1d7b6093 100644 --- a/README_TR.md +++ b/README_TR.md @@ -133,7 +133,7 @@ MaxMind hesabınızdan `GeoLite2-City.mmdb` ve `GeoLite2-ASN.mmdb` dosyalarını | `FRONTEND_PORT` | Hayır | `"18966"` | Frontend kısmının çalıştığı port | | `SECURITY_RATE_LIMIT` | Hayır | `"0"` | Bir IP'nin backend sunucusuna 60 dakikada yapabileceği istek sayısını kontrol eder (sınır yok için 0) | | `SECURITY_DELAY_AFTER` | Hayır | `"0"` | 20 dakikada bir IP'den gelen ilk X isteğin hız sınırına tabi olmadığını kontrol eder; X'ten sonra gecikme artar | -| `SECURITY_BLACKLIST_LOG_FILE_PATH` | Hayır | `"logs/blacklist-ip.log"` | Yol ayarı. SECURITY_RATE_LIMIT etkinleştirildiğinde limit tetikleyen IP'leri kaydeder | +| `SECURITY_BLACKLIST_LOG_FILE_PATH` | Hayır | `""` | Hız sınırına takılan IP'lerin isteğe bağlı yerel kayıt dosyası (örn. `"logs/blacklist-ip.log"`). Boş bırakılırsa dosya yazılmaz; olay her durumda paylaşılan logger ile loglanır | | `LOG_LEVEL` | Hayır | `"info"` | Minimum log seviyesi (`debug` / `info` / `warn` / `error`). Daha düşük seviyedeki mesajlar bastırılır. | | `LOG_FORMAT` | Hayır | pretty | `"json"` olarak ayarlandığında satır başına bir JSON olayı çıkarır (log toplayıcılar / jq için). Diğer değerler (veya ayarlanmamışsa) dev ortamında ve pm2 log tail sırasında kullanılan renkli güzel biçimli çıktıyı korur. | | `LOG_HTTP` | Hayır | `"false"` | `"true"` yapıldığında `/api/*` üzerinde istek başı HTTP loglamasını etkinleştirir (metod, URL, durum, yanıt süresi). pm2 loglarını küçük tutmak için varsayılan olarak kapalıdır. Bu bayrak kapalı olsa bile handler düzeyindeki 4xx/5xx hataları her zaman loglanır. | @@ -235,8 +235,8 @@ Yapay zekâ sayesinde, işsiz bir ürün yöneticisi olarak programlamayı hızl Açık kaynak proje olarak, destekleri için aşağıdaki sponsorlarımıza minnettarım: - + -Cloudflare Project Alexandria +Cloudflare Project Alexandria -Sentry +Sentry diff --git a/README_ZH.md b/README_ZH.md index 0bf3ba5a..b65fd206 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -133,7 +133,7 @@ MyIP 依赖 MaxMind 提供的免费 **GeoLite2** 数据库(City + ASN)来进 | `FRONTEND_PORT` | 否 | `"18966"` | 程序前端部分的运行端口 | | `SECURITY_RATE_LIMIT` | 否 | `"0"` | 控制每 60 分钟一个 IP 可以对后端服务器请求的次数(设置为 0 则为不限制) | | `SECURITY_DELAY_AFTER` | 否 | `"0"` | 控制每 20 分钟一个 IP 的前 X 次请求不受速度限制,超过 X 次后会逐次增加延迟 | -| `SECURITY_BLACKLIST_LOG_FILE_PATH` | 否 | `"logs/blacklist-ip.log"` | 路径设置。记录由 SECURITY_RATE_LIMIT 开启后,触发限制的 IP 列表 | +| `SECURITY_BLACKLIST_LOG_FILE_PATH` | 否 | `""` | 可选的本地黑名单文件(如 `"logs/blacklist-ip.log"`),记录触发限流的 IP。留空则不写文件;无论是否设置,事件都会通过共享 logger 记录 | | `LOG_LEVEL` | 否 | `"info"` | 日志最低级别(`debug` / `info` / `warn` / `error`),低于该级别的日志会被过滤 | | `LOG_FORMAT` | 否 | pretty | 设置为 `"json"` 时每行输出一个 JSON 事件(给日志聚合器 / jq 使用);其它值(或未设置)则使用带颜色的 pretty 格式,适合开发及 pm2 log tail | | `LOG_HTTP` | 否 | `"false"` | 设置为 `"true"` 时启用 `/api/*` 的按请求日志(方法、URL、状态码、响应时间)。默认关闭以控制 pm2 日志体积。即使关闭,handler 层的 4xx/5xx 错误日志依然会被记录 | @@ -236,8 +236,8 @@ DOMAIN,ptest-8.ipcheck.ing,Proxy8 作为一个开源项目,我非常感谢以下赞助者对我的支持: - + -Cloudflare Project Alexandria +Cloudflare Project Alexandria -Sentry +Sentry