From 547e78c09630c55cff6df0e8ed700e2f1443faad Mon Sep 17 00:00:00 2001 From: Aditya Mathur Date: Wed, 20 Mar 2024 15:50:49 +0530 Subject: [PATCH] chore(sandbox): added vercel kv --- apps/sandbox/src/main.tsx | 6 +- package.json | 117 +++++++++++++++++++------------------- pnpm-lock.yaml | 20 +++++++ 3 files changed, 84 insertions(+), 59 deletions(-) diff --git a/apps/sandbox/src/main.tsx b/apps/sandbox/src/main.tsx index 8b2fd44..1184939 100644 --- a/apps/sandbox/src/main.tsx +++ b/apps/sandbox/src/main.tsx @@ -1,6 +1,7 @@ import { serve } from "@hono/node-server"; +import { kv } from "@vercel/kv"; import { Hono } from "hono"; -import { type RateLimitInfo, rateLimiter } from "hono-rate-limiter"; +import { type RateLimitInfo, RedisStore, rateLimiter } from "hono-rate-limiter"; import { logger } from "hono/logger"; import Page from "./Page"; @@ -17,6 +18,9 @@ app.use( rateLimiter({ windowMs: 10_000, limit: 10, + // store: new RedisStore({ + // sendCommand: (...args: string[]) => kv(args), + // }), handler: (_, next) => next(), }), ); diff --git a/package.json b/package.json index 289a298..b394518 100644 --- a/package.json +++ b/package.json @@ -1,58 +1,59 @@ -{ - "name": "@hono-ratelimiter/source", - "version": "0.0.0", - "license": "MIT", - "scripts": { - "commit": "czg", - "prepare": "is-ci || husky install", - "format": "biome check --apply ." - }, - "private": true, - "dependencies": { - "@hono/node-server": "^1.8.2", - "hono": "^4.1.1" - }, - "devDependencies": { - "@biomejs/biome": "^1.6.1", - "@jscutlery/semver": "^5.2.0", - "@nx/esbuild": "18.1.1", - "@nx/eslint": "18.1.1", - "@nx/eslint-plugin": "18.1.1", - "@nx/js": "18.1.1", - "@nx/node": "18.1.1", - "@nx/vite": "18.1.1", - "@nx/web": "18.1.1", - "@nx/workspace": "18.1.1", - "@swc-node/register": "~1.8.0", - "@swc/cli": "~0.1.62", - "@swc/core": "~1.3.85", - "@swc/helpers": "~0.5.2", - "@types/ioredis-mock": "^8.2.5", - "@types/node": "18.16.9", - "@types/supertest": "^6.0.2", - "@typescript-eslint/eslint-plugin": "^6.13.2", - "@typescript-eslint/parser": "^6.13.2", - "@vitest/coverage-v8": "^1.0.4", - "@vitest/ui": "^1.3.1", - "czg": "^1.9.0", - "esbuild": "^0.19.2", - "eslint": "~8.48.0", - "eslint-config-prettier": "^9.0.0", - "husky": "^9.0.11", - "ioredis-mock": "^8.9.0", - "is-ci": "^3.0.1", - "lint-staged": "^15.2.2", - "ngx-deploy-npm": "^8.0.1", - "nx": "18.1.1", - "prettier": "^2.6.2", - "supertest": "^6.3.4", - "tslib": "^2.6.2", - "typescript": "~5.3.2", - "verdaccio": "^5.0.4", - "vite": "~5.0.0", - "vitest": "^1.3.1" - }, - "nx": { - "includedScripts": [] - } -} +{ + "name": "@hono-ratelimiter/source", + "version": "0.0.0", + "license": "MIT", + "scripts": { + "commit": "czg", + "prepare": "is-ci || husky install", + "format": "biome check --apply ." + }, + "private": true, + "dependencies": { + "@hono/node-server": "^1.8.2", + "@vercel/kv": "^1.0.1", + "hono": "^4.1.1" + }, + "devDependencies": { + "@biomejs/biome": "^1.6.1", + "@jscutlery/semver": "^5.2.0", + "@nx/esbuild": "18.1.1", + "@nx/eslint": "18.1.1", + "@nx/eslint-plugin": "18.1.1", + "@nx/js": "18.1.1", + "@nx/node": "18.1.1", + "@nx/vite": "18.1.1", + "@nx/web": "18.1.1", + "@nx/workspace": "18.1.1", + "@swc-node/register": "~1.8.0", + "@swc/cli": "~0.1.62", + "@swc/core": "~1.3.85", + "@swc/helpers": "~0.5.2", + "@types/ioredis-mock": "^8.2.5", + "@types/node": "18.16.9", + "@types/supertest": "^6.0.2", + "@typescript-eslint/eslint-plugin": "^6.13.2", + "@typescript-eslint/parser": "^6.13.2", + "@vitest/coverage-v8": "^1.0.4", + "@vitest/ui": "^1.3.1", + "czg": "^1.9.0", + "esbuild": "^0.19.2", + "eslint": "~8.48.0", + "eslint-config-prettier": "^9.0.0", + "husky": "^9.0.11", + "ioredis-mock": "^8.9.0", + "is-ci": "^3.0.1", + "lint-staged": "^15.2.2", + "ngx-deploy-npm": "^8.0.1", + "nx": "18.1.1", + "prettier": "^2.6.2", + "supertest": "^6.3.4", + "tslib": "^2.6.2", + "typescript": "~5.3.2", + "verdaccio": "^5.0.4", + "vite": "~5.0.0", + "vitest": "^1.3.1" + }, + "nx": { + "includedScripts": [] + } +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1e48bd4..f6daf52 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,6 +8,9 @@ dependencies: '@hono/node-server': specifier: ^1.8.2 version: 1.8.2 + '@vercel/kv': + specifier: ^1.0.1 + version: 1.0.1 hono: specifier: ^4.1.1 version: 4.1.1 @@ -3298,6 +3301,19 @@ packages: eslint-visitor-keys: 3.4.3 dev: true + /@upstash/redis@1.25.1: + resolution: {integrity: sha512-ACj0GhJ4qrQyBshwFgPod6XufVEfKX2wcaihsEvSdLYnY+m+pa13kGt1RXm/yTHKf4TQi/Dy2A8z/y6WUEOmlg==} + dependencies: + crypto-js: 4.2.0 + dev: false + + /@vercel/kv@1.0.1: + resolution: {integrity: sha512-uTKddsqVYS2GRAM/QMNNXCTuw9N742mLoGRXoNDcyECaxEXvIHG0dEY+ZnYISV4Vz534VwJO+64fd9XeSggSKw==} + engines: {node: '>=14.6'} + dependencies: + '@upstash/redis': 1.25.1 + dev: false + /@verdaccio/commons-api@10.2.0: resolution: {integrity: sha512-F/YZANu4DmpcEV0jronzI7v2fGVWkQ5Mwi+bVmV+ACJ+EzR0c9Jbhtbe5QyLUuzR97t8R5E/Xe53O0cc2LukdQ==} engines: {node: '>=8'} @@ -4614,6 +4630,10 @@ packages: which: 2.0.2 dev: true + /crypto-js@4.2.0: + resolution: {integrity: sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q==} + dev: false + /czg@1.9.0: resolution: {integrity: sha512-cYmC5/99kUGlnK1D8uXr4hykzC50MqzpMp3SlrE+w8wVzd9+0XxKsjWXhi+QIuDnzkx2CCvKSMT4xwDeaOD/xg==} engines: {node: '>=v12.20.0'}