From d37b564d2eb78f264d924d57c7ed605b2705620d Mon Sep 17 00:00:00 2001 From: Andrew Date: Fri, 25 Oct 2024 16:44:38 -0400 Subject: [PATCH 1/4] rate limiter + translations --- src/client/app/translations/data.ts | 18 ++++++++++++++ src/server/app.js | 37 +++++++++++++++++++++++++++-- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/src/client/app/translations/data.ts b/src/client/app/translations/data.ts index 740311d8c..71230ec06 100644 --- a/src/client/app/translations/data.ts +++ b/src/client/app/translations/data.ts @@ -392,10 +392,16 @@ const LocaleTranslationData = { "radar.lines.incompatible": "These meters/groups are not compatible for radar graphs", "radar.no.data": "There are no readings:
likely the data range is outside meter/group reading range", "rate": "Rate", + "rate.limit.error.first": "You have been rate limited by your OED site", + "rate.limit.error.second": "We suggest you try these in this order:", "reading": "Reading:", "redo.cik.and.refresh.db.views": "Processing changes. This may take a while.", "readings.per.day": "Readings per Day", "redraw": "Redraw", + "refresh.page.first": "Click the Refresh this page' button below to try again", + "refresh.page.second": "If you keep returning to this page wait longer and click 'Refresh this page' button", + "refresh.page.third": "Contact your site to find why the rate limit is denying access to the OED site", + "refresh.window": "Refresh this page", "remove": "Remove", "restore": "Restore", "return.dashboard": "Return To Dashboard", @@ -893,10 +899,16 @@ const LocaleTranslationData = { "radar.lines.incompatible": "These meters/groups are not compatible for radar graphs\u{26A1}", "radar.no.data": "There are no readings:
likely the data range is outside meter/group reading range\u{26A1}", "rate": "Rate\u{26A1}", + "rate.limit.error.first": "You have been rate limited by your OED site\u{26A1}", + "rate.limit.error.second": "We suggest you try these in this order:\u{26A1}", "reading": "Reading:\u{26A1}", "redo.cik.and.refresh.db.views": "Processing changes. This may take a while\u{26A1}", "readings.per.day": "Readings per Day\u{26A1}", "redraw": "Redessiner", + "refresh.page.first": "Click the Refresh this page' button below to try again\u{26A1}", + "refresh.page.second": "If you keep returning to this page wait longer and click 'Refresh this page' button\u{26A1}", + "refresh.page.third": "Contact your site to find why the rate limit is denying access to the OED site\u{26A1}", + "refresh.window": "Refresh this page\u{26A1}", "remove": "Remove\u{26A1}", "restore": "Restaurer", "return.dashboard": "Return To Dashboard\u{26A1}", @@ -1395,10 +1407,16 @@ const LocaleTranslationData = { "radar.lines.incompatible": "Estos medidores/grupos no son compatibles para gráficos de radares", "radar.no.data": "No hay lecturas:
es probable que el rango de los datos esté fuera del rango de lecturas de los medidores/grupos", "rate": "Tasa", + "rate.limit.error.first": "You have been rate limited by your OED site\u{26A1}", + "rate.limit.error.second": "We suggest you try these in this order:\u{26A1}", "reading": "Lectura:", "redo.cik.and.refresh.db.views": "Procesando los cambios. Esto tardará un momento.", "readings.per.day": "Lecturas por día", "redraw": "Redibujar", + "refresh.page.first": "Click the Refresh this page' button below to try again\u{26A1}", + "refresh.page.second": "If you keep returning to this page wait longer and click 'Refresh this page' button\u{26A1}", + "refresh.page.third": "Contact your site to find why the rate limit is denying access to the OED site\u{26A1}", + "refresh.window": "Refresh this page\u{26A1}", "remove": "Eliminar", "restore": "Restaurar", "return.dashboard": "Regresar al panel principal", diff --git a/src/server/app.js b/src/server/app.js index 58774f9cc..bfe434255 100644 --- a/src/server/app.js +++ b/src/server/app.js @@ -41,10 +41,43 @@ const generalLimiter = rateLimit({ windowMs: 5 * 1000, // 5 seconds limit: 200, // 200 requests standardHeaders: true, // Return rate limit info in the `RateLimit-*` headers - legacyHeaders: false // Disable the `X-RateLimit-*` headers + legacyHeaders: false, // Disable the `X-RateLimit-*` headers + // If rate limit is 10, OED won't load and bad things will happen + message: async(req,res) => { + let string = ` +

+ You have been rate limited by your OED site +

+

+ We suggest you try these in this order: +

+

+

+
+
    +
  1. + Click the 'Refresh this page' button below to try again +
  2. +
  3. + If you keep returning to this page wait longer and click 'Refresh this page' button +
  4. +
  5. + Contact your site to find why the rate limit is denying access to the OED site +
  6. +
+
+

+ +

+ ` + return string + } }); // Apply the limit to overall requests -const app = express().use(generalLimiter); +const app = express().use(generalLimiter); // This is limiting 3D-Graphic const threeDLimiter = rateLimit({ From 1e817b62542c8d585a02b0fbdccabef75f961010 Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 14 Nov 2024 12:14:48 -0500 Subject: [PATCH 2/4] Resolve comments from PR --- src/server/app.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/server/app.js b/src/server/app.js index bfe434255..bfb561204 100644 --- a/src/server/app.js +++ b/src/server/app.js @@ -39,14 +39,14 @@ const ciks = require('./routes/ciks'); // Create a limit of 200 requests/5 seconds const generalLimiter = rateLimit({ windowMs: 5 * 1000, // 5 seconds - limit: 200, // 200 requests + limit: 10, // 200 requests standardHeaders: true, // Return rate limit info in the `RateLimit-*` headers legacyHeaders: false, // Disable the `X-RateLimit-*` headers // If rate limit is 10, OED won't load and bad things will happen message: async(req,res) => { - let string = ` + const string = `

- You have been rate limited by your OED site + You have been rate limited by your OED site.

We suggest you try these in this order: @@ -57,13 +57,13 @@ const generalLimiter = rateLimit({
  1. - Click the 'Refresh this page' button below to try again + Click the 'Refresh this page' button below to try again.
  2. - If you keep returning to this page wait longer and click 'Refresh this page' button + If you keep returning to this page wait longer and click 'Refresh this page' button.
  3. - Contact your site to find why the rate limit is denying access to the OED site + Contact your site to find why the rate limit is denying access to the OED site.
From 3f595976b8073cde06123369404c03a7469d9bb4 Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 14 Nov 2024 12:59:08 -0500 Subject: [PATCH 3/4] Fix rate limit set at 10 instead of 200 --- src/server/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/app.js b/src/server/app.js index bfb561204..929ec61bc 100644 --- a/src/server/app.js +++ b/src/server/app.js @@ -39,7 +39,7 @@ const ciks = require('./routes/ciks'); // Create a limit of 200 requests/5 seconds const generalLimiter = rateLimit({ windowMs: 5 * 1000, // 5 seconds - limit: 10, // 200 requests + limit: 200, // 200 requests standardHeaders: true, // Return rate limit info in the `RateLimit-*` headers legacyHeaders: false, // Disable the `X-RateLimit-*` headers // If rate limit is 10, OED won't load and bad things will happen From 1b4c9abbfe529e68cdaff8086d26d8351185cbcc Mon Sep 17 00:00:00 2001 From: Steven Huss-Lederman Date: Thu, 14 Nov 2024 14:39:33 -0600 Subject: [PATCH 4/4] format document Doing this since I accidently forgot to post --- src/server/app.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/server/app.js b/src/server/app.js index 929ec61bc..ad297a27d 100644 --- a/src/server/app.js +++ b/src/server/app.js @@ -43,7 +43,7 @@ const generalLimiter = rateLimit({ standardHeaders: true, // Return rate limit info in the `RateLimit-*` headers legacyHeaders: false, // Disable the `X-RateLimit-*` headers // If rate limit is 10, OED won't load and bad things will happen - message: async(req,res) => { + message: async (req, res) => { const string = `

You have been rate limited by your OED site. @@ -77,7 +77,7 @@ const generalLimiter = rateLimit({ } }); // Apply the limit to overall requests -const app = express().use(generalLimiter); +const app = express().use(generalLimiter); // This is limiting 3D-Graphic const threeDLimiter = rateLimit({