Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

Stopping Chat Spam on Netlify with a Simple Rate‑Limit

说明与用途

在 Netlify 上阻止聊天垃圾邮件的简单方法:在 Postgres 中存储计数器,在 Edge Function 中检查请求,并在超过限制时返回友好的 JSON 错误。

问题

Public chat endpoints can be flooded with bot messages, degrading user experience.

结果

Spam traffic is reduced, backend load is protected, and users receive clear feedback, all without additional SaaS costs.

工作流

  • Persist a lightweight counter in Postgres: store a row per IP or user token with timestamp and hit count, resetting if older than a day.
  • Gate the request with a Netlify Edge Function: read the counter before the request reaches the main API, short‑circuit with 429 if threshold exceeded (e.g., 5 messages per minute).
  • Return a friendly JSON payload: {"error": "Rate limit exceeded – please wait a moment before sending another message."} to inform users and bots.

证据

Persist a lightweight counter in Postgres. I store a row per IP address (or per user token) with a timestamp and a hit count.

来源

Gate the request with a Netlify Edge Function. The Edge Function reads the counter before the request reaches my main API. If the count exceeds the threshold (e.g., 5 messages per minute), the function short‑circuits and returns a 429 response.

来源

Give a friendly “slow down” message. Instead of a generic error, I return a short JSON payload: { "error": "Rate limit exceeded – please wait a moment before sending another message." }

来源

  • 记录日期: 2026-10-16T13:56:17.404Z