opacacms 0.1.9 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.js +1 -1
- package/dist/{chunk-hmhcense.js → chunk-0nf7fe26.js} +7 -2
- package/dist/runtimes/bun.js +1 -1
- package/dist/runtimes/cloudflare-workers.js +1 -1
- package/dist/runtimes/next.js +1 -1
- package/dist/runtimes/node.js +1 -1
- package/dist/server/middlewares/rate-limit.d.ts +1 -1
- package/dist/server.js +1 -1
- package/package.json +1 -1
- package/src/server/middlewares/rate-limit.ts +9 -3
package/dist/api.js
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
init_system_schema
|
|
15
15
|
} from "./chunk-ybbbqj63.js";
|
|
16
16
|
import {
|
|
17
|
+
__require,
|
|
17
18
|
__toCommonJS
|
|
18
19
|
} from "./chunk-8sqjbsgt.js";
|
|
19
20
|
|
|
@@ -1000,7 +1001,6 @@ function createDatabaseInitMiddleware(config, state) {
|
|
|
1000
1001
|
}
|
|
1001
1002
|
|
|
1002
1003
|
// src/server/middlewares/rate-limit.ts
|
|
1003
|
-
import { WorkersKVStore } from "@hono-rate-limiter/cloudflare";
|
|
1004
1004
|
import { rateLimiter } from "hono-rate-limiter";
|
|
1005
1005
|
function createRateLimitMiddleware(config) {
|
|
1006
1006
|
const rateLimitConfig = config.api?.rateLimit;
|
|
@@ -1028,7 +1028,12 @@ function createRateLimitMiddleware(config) {
|
|
|
1028
1028
|
if (!resolvedStore && c.env) {
|
|
1029
1029
|
const kvBindingKey = Object.keys(c.env).find((key) => key.startsWith("OPACA_") && c.env[key]?.put && c.env[key]?.get);
|
|
1030
1030
|
if (kvBindingKey) {
|
|
1031
|
-
|
|
1031
|
+
try {
|
|
1032
|
+
const { WorkersKVStore } = await import("@hono-rate-limiter/cloudflare");
|
|
1033
|
+
resolvedStore = new WorkersKVStore({ namespace: c.env[kvBindingKey] });
|
|
1034
|
+
} catch (e) {
|
|
1035
|
+
logger.error("Failed to load @hono-rate-limiter/cloudflare dynamic import. Make sure you are in a Cloudflare environment.", e);
|
|
1036
|
+
}
|
|
1032
1037
|
}
|
|
1033
1038
|
}
|
|
1034
1039
|
const limiter = rateLimiter({
|
package/dist/runtimes/bun.js
CHANGED
package/dist/runtimes/next.js
CHANGED
package/dist/runtimes/node.js
CHANGED
package/dist/server.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
2
|
import type { Context, MiddlewareHandler } from "hono";
|
|
3
3
|
import { rateLimiter } from "hono-rate-limiter";
|
|
4
|
-
import type { OpacaConfig } from "
|
|
4
|
+
import type { OpacaConfig } from "@/types";
|
|
5
|
+
import { logger } from "@/utils/logger";
|
|
5
6
|
|
|
6
7
|
export function createRateLimitMiddleware(config: OpacaConfig): MiddlewareHandler {
|
|
7
8
|
const rateLimitConfig = config.api?.rateLimit;
|
|
@@ -50,7 +51,12 @@ export function createRateLimitMiddleware(config: OpacaConfig): MiddlewareHandle
|
|
|
50
51
|
);
|
|
51
52
|
|
|
52
53
|
if (kvBindingKey) {
|
|
53
|
-
|
|
54
|
+
try {
|
|
55
|
+
const { WorkersKVStore } = await import("@hono-rate-limiter/cloudflare");
|
|
56
|
+
resolvedStore = new WorkersKVStore({ namespace: (c.env as any)[kvBindingKey] });
|
|
57
|
+
} catch (e) {
|
|
58
|
+
logger.error("Failed to load @hono-rate-limiter/cloudflare dynamic import. Make sure you are in a Cloudflare environment.", e);
|
|
59
|
+
}
|
|
54
60
|
}
|
|
55
61
|
}
|
|
56
62
|
|