feat(api): ratelimiting
because some group of idiots like me so much that they spam my endpoint
This commit is contained in:
parent
9e91f608b9
commit
a69a834899
@ -7,6 +7,14 @@ export default defineEventHandler(async (event) => {
|
|||||||
FeedbackSchema.parseAsync
|
FeedbackSchema.parseAsync
|
||||||
)
|
)
|
||||||
const env = useRuntimeConfig(event)
|
const env = useRuntimeConfig(event)
|
||||||
|
const { pathname } = new URL(event.node.req.url)
|
||||||
|
|
||||||
|
const { success } = await env.MY_RATE_LIMITER.limit({ key: pathname })
|
||||||
|
if (!success) {
|
||||||
|
return new Response(`429 Failure – rate limit exceeded for ${pathname}`, {
|
||||||
|
status: 429
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
let description = `${message}\n\n`
|
let description = `${message}\n\n`
|
||||||
if (page) description += `**Page:** \`${page}\``
|
if (page) description += `**Page:** \`${page}\``
|
||||||
|
@ -36,11 +36,9 @@
|
|||||||
"@iconify-json/carbon": "^1.1.28",
|
"@iconify-json/carbon": "^1.1.28",
|
||||||
"@iconify-json/heroicons-solid": "^1.1.11",
|
"@iconify-json/heroicons-solid": "^1.1.11",
|
||||||
"@iconify-json/twemoji": "^1.1.15",
|
"@iconify-json/twemoji": "^1.1.15",
|
||||||
"@taskylizard/eslint-config": "^1.1.1",
|
|
||||||
"@types/fs-extra": "^11.0.4",
|
"@types/fs-extra": "^11.0.4",
|
||||||
"@types/node": "^20.11.15",
|
"@types/node": "^20.11.15",
|
||||||
"@types/nprogress": "^0.2.3",
|
"@types/nprogress": "^0.2.3",
|
||||||
"eslint": "^8.56.0",
|
|
||||||
"prettier": "^3.2.4",
|
"prettier": "^3.2.4",
|
||||||
"tailwindcss": "^3.4.4"
|
"tailwindcss": "^3.4.4"
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,32 @@
|
|||||||
{
|
{
|
||||||
"extends": "./.nitro/types/tsconfig.json",
|
"extends": "./.nitro/types/tsconfig.json"
|
||||||
"compilerOptions": {
|
// "compilerOptions": {
|
||||||
"verbatimModuleSyntax": true
|
// "verbatimModuleSyntax": true,
|
||||||
},
|
// "baseUrl": ".",
|
||||||
"include": ["./.vitepress/"]
|
// "module": "esnext",
|
||||||
|
// "target": "esnext",
|
||||||
|
// "lib": ["DOM", "ESNext"],
|
||||||
|
// "strict": true,
|
||||||
|
// "jsx": "preserve",
|
||||||
|
// "esModuleInterop": true,
|
||||||
|
// "skipLibCheck": true,
|
||||||
|
// "moduleResolution": "node",
|
||||||
|
// "resolveJsonModule": true,
|
||||||
|
// "noUnusedLocals": true,
|
||||||
|
// "strictNullChecks": true,
|
||||||
|
// "forceConsistentCasingInFileNames": true,
|
||||||
|
// "sourceMap": true,
|
||||||
|
// "isolatedModules": true
|
||||||
|
// },
|
||||||
|
// "include": [
|
||||||
|
// "**/*.vue",
|
||||||
|
// "**/*.tsx",
|
||||||
|
// "**/*.ts",
|
||||||
|
// ".vitepress/**/**/*.ts",
|
||||||
|
// ".vitepress/**/**/*.tsx",
|
||||||
|
// ".vitepress/**/**/*.vue"
|
||||||
|
// ],
|
||||||
|
// "exclude": ["**/node_modules/**", "dist/**"],
|
||||||
|
// "extensions": [".js", ".ts", ".tsx", ".jsx", ".vue"],
|
||||||
|
// "allowSyntheticDefaultImports": true
|
||||||
}
|
}
|
||||||
|
@ -3,3 +3,9 @@ main = ".output/server/index.mjs"
|
|||||||
workers_dev = true
|
workers_dev = true
|
||||||
account_id = "fe5d9bd14160b07939282e45f63eb5ad"
|
account_id = "fe5d9bd14160b07939282e45f63eb5ad"
|
||||||
compatibility_date = "2022-09-10"
|
compatibility_date = "2022-09-10"
|
||||||
|
|
||||||
|
[[unsafe.bindings]]
|
||||||
|
name = "RATE_LIMITER"
|
||||||
|
type = "ratelimit"
|
||||||
|
namespace_id = "1001"
|
||||||
|
simple = { limit = 100, period = 30 }
|
||||||
|
Loading…
Reference in New Issue
Block a user