mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-11-07 12:33:36 +09:00
## Description This PR integrates a rate-limiting mechanism into the app using Vercel's edge-layer middleware in combination with the Hono framework. This middleware is written in JS with full JSDoc TypeScript typings. ### Architecture & Strategy Vercel Middleware: Serves as the front-line defense, running at the edge for optimal performance. Hono Framework: For granular control, we utilize Hono middlewares for applying or skipping rate limits. Additionally, non-expensive routes benefit from an ephemeral cache to further optimize performance ### Current Limitations Due to a dependency on CommonJS, we cannot use TypeScript fully. Consequently, session configurations are not yet shared across multiple files. All utility functions are present in a single file for the time being. ### Logic Breakdown - Assets: Rate limiting skipped. - Service Calls: Rate limiting skipped. - /rest/ai/* Endpoint: Rate limit of 20 requests per 5 minutes, identified by userId or IP. - Unauthorized Users: Rate limit of 5 requests per 5 seconds, based solely on IP. - Authorized Users: Rate limit of 20 requests per 5 seconds, based on userId. ### Next Steps Plan to migrate to ESM for enabling TypeScript support for better maintainability. Use multiple regional KV ### Debug endpoint. [Rate limit debug endpoint](https://webstudio-builder-kscynssns-webstudio-is.vercel.app/rate-limit-debug) ## Steps for reproduction 1. click button 2. expect xyz ## Code Review - [ ] hi @kof, I need you to do - conceptual review (architecture, feature-correctness) - detailed review (read every line) - test it on preview ## Before requesting a review - [ ] made a self-review - [ ] added inline comments where things may be not obvious (the "why", not "what") ## Before merging - [ ] tested locally and on preview environment (preview dev login: 5de6) - [ ] updated [test cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md) document - [ ] added tests - [ ] if any new env variables are added, added them to `.env.example` and the `builder/env-check.js` if mandatory
73 lines
2.7 KiB
JSON
73 lines
2.7 KiB
JSON
{
|
|
"packageManager": "pnpm@8.8.0",
|
|
"name": "webstudio",
|
|
"version": "0.0.0",
|
|
"private": true,
|
|
"scripts": {
|
|
"build": "turbo run build --filter='!./fixtures/*'",
|
|
"build-packages": "turbo run build --filter=\"!@webstudio-is/builder\"",
|
|
"dts": "turbo run dts",
|
|
"size-test": "turbo run size-test",
|
|
"checks": "turbo run checks",
|
|
"dev": "pnpm --filter='!./fixtures/*' run --parallel --recursive dev",
|
|
"lint": "pnpm eslint . --ext .ts,.tsx --max-warnings 0",
|
|
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
|
|
"storybook": "pnpm run --parallel --recursive storybook:dev",
|
|
"storybook:build": "storybook build",
|
|
"migrations": "cd apps/builder && pnpm migrations --dev",
|
|
"build-figma-tokens": "cd packages/design-system && pnpm build-figma-tokens",
|
|
"prepare": "git config core.hooksPath .git/hooks/ && simple-git-hooks",
|
|
"local:version-snapshot": "pnpm -r exec pnpm version prepatch --preid $(cat /dev/urandom | LC_ALL=C tr -dc 'a-z' | fold -w 8 | head -n 1)",
|
|
"local:publish-snapshot": "pnpm -r publish --access public --no-git-checks --registry http://localhost:4873",
|
|
"local:dangerously-undo-version-snapshot": "git restore --source=$(git branch --show-current) '**/*/package.json'",
|
|
"local:release": "pnpm build && pnpm dts && pnpm local:version-snapshot && pnpm local:publish-snapshot && pnpm local:dangerously-undo-version-snapshot && echo \"now execute\npnpm up -r -L '@webstudio-is/*' --registry http://localhost:4873\""
|
|
},
|
|
"simple-git-hooks": {
|
|
"pre-commit": "./node_modules/.bin/nano-staged"
|
|
},
|
|
"devDependencies": {
|
|
"@storybook/react-vite": "^7.4.0",
|
|
"@types/css-tree": "^2.3.1",
|
|
"@webstudio-is/eslint-config-custom": "workspace:*",
|
|
"esbuild": "^0.19.2",
|
|
"nano-staged": "^0.8.0",
|
|
"prettier": "3.0.3",
|
|
"simple-git-hooks": "^2.9.0",
|
|
"storybook": "^7.4.0",
|
|
"tsx": "^3.12.8",
|
|
"turbo": "^1.8.6",
|
|
"typescript": "5.2.2"
|
|
},
|
|
"engines": {
|
|
"node": "18",
|
|
"pnpm": "8.8",
|
|
"yarn": "This project is configured to use pnpm"
|
|
},
|
|
"nano-staged": {
|
|
"*.{ts,tsx,js,json,css,md}": "prettier --write"
|
|
},
|
|
"prettier": {
|
|
"trailingComma": "es5",
|
|
"overrides": [
|
|
{
|
|
"files": [
|
|
"*.ts",
|
|
"*.tsx"
|
|
],
|
|
"options": {
|
|
"parser": "babel-ts"
|
|
}
|
|
}
|
|
]
|
|
},
|
|
"pnpm": {
|
|
"patchedDependencies": {
|
|
"@stitches/react@1.3.1-1": "patches/@stitches__react@1.3.1-1.patch",
|
|
"css-tree@2.3.1": "patches/css-tree@2.3.1.patch",
|
|
"@types/css-tree@2.3.1": "patches/@types__css-tree@2.3.1.patch",
|
|
"@radix-ui/react-focus-scope@1.0.3": "patches/@radix-ui__react-focus-scope@1.0.3.patch",
|
|
"@cloudflare/workers-types@3.19.0": "patches/@cloudflare__workers-types@3.19.0.patch"
|
|
}
|
|
}
|
|
}
|