pull/2293/head
Jérémy Rialland 2022-09-15 10:15:41 +02:00 committed by Jérémy Rialland
parent 4d85612b2d
commit 1ae08b887e
2 changed files with 8 additions and 3 deletions

View File

@ -44,6 +44,7 @@ export const plausibleMiddleware = async (
void plausibleEvent(ctx, { eventName: 'pageview' }).catch((err) => {
const error = err as RequestError
// eslint-disable-next-line no-console
console.error(error.code, error.message)
})
@ -56,6 +57,7 @@ export const plausibleMiddleware = async (
},
}).catch((err) => {
const error = err as RequestError
// eslint-disable-next-line no-console
console.error(error.code, error.message)
})

View File

@ -1,5 +1,5 @@
import IORedis from 'ioredis'
import { BaseContext, Next } from 'koa'
import { BaseContext } from 'koa'
import {
RateLimiterMemory,
RateLimiterRedis,
@ -23,7 +23,10 @@ const rateLimiter =
duration: 1, // per 1 seconds
})
export const rateLimiterMiddleware = async (ctx: BaseContext, next: Next) => {
export const rateLimiterMiddleware = async (
ctx: BaseContext,
next: () => Promise<unknown>
) => {
try {
await rateLimiter.consume(ctx.ip)
} catch (rejRes) {
@ -44,7 +47,7 @@ export const rateLimiterMiddleware = async (ctx: BaseContext, next: Next) => {
return
}
return (await next()) as unknown
return await next()
}
const isRateLimiterRes = (val: unknown): val is RateLimiterRes => {