Skip to content

Commit

Permalink
Merge pull request #1370 from zhenga5/Rate-Limit
Browse files Browse the repository at this point in the history
rate limiter + translations
  • Loading branch information
huss authored Nov 14, 2024
2 parents be1abbf + 1b4c9ab commit 5cb4831
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/client/app/translations/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,16 @@ const LocaleTranslationData = {
"radar.lines.incompatible": "These meters/groups are not compatible for radar graphs",
"radar.no.data": "There are no readings:<br>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",
Expand Down Expand Up @@ -901,10 +907,16 @@ const LocaleTranslationData = {
"radar.lines.incompatible": "These meters/groups are not compatible for radar graphs\u{26A1}",
"radar.no.data": "There are no readings:<br>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}",
Expand Down Expand Up @@ -1408,10 +1420,16 @@ const LocaleTranslationData = {
"radar.lines.incompatible": "Estos medidores/grupos no son compatibles para gráficos de radares",
"radar.no.data": "No hay lecturas:<br>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",
Expand Down
35 changes: 34 additions & 1 deletion src/server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,40 @@ 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) => {
const string = `
<h1 style='text-align:center'>
You have been rate limited by your OED site.
</h1>
<h2 style ='text-align:center'>
We suggest you try these in this order:
</h2>
<h2
style='text-align:center'>
</h2>
<div>
<ol style = "text-align: center; list-style-position: inside;">
<li>
Click the 'Refresh this page' button below to try again.
</li>
<li>
If you keep returning to this page wait longer and click 'Refresh this page' button.
</li>
<li>
Contact your site to find why the rate limit is denying access to the OED site.
</li>
</ol>
</div>
<h3 style='text-align:center'>
<button onClick='window.location.reload();'>
Refresh this page
</button>
</h3>
`
return string
}
});
// Apply the limit to overall requests
const app = express().use(generalLimiter);
Expand Down

0 comments on commit 5cb4831

Please sign in to comment.