Closed exoer closed 1 year ago
The remote address will be exposed with this PR: https://github.com/Effect-TS/platform/pull/148
Your example can updated to the following:
export const limited = make((httpApp) =>
Effect.flatMap(ServerRequest.ServerRequest, (request) =>
Effect.tryPromise(() =>
rateLimiter.consume(Option.getOrUndefined(request.remoteAddress)),
).pipe(
Effect.match({
onFailure: () => Effect.succeed(Http.response.empty({ status: 429 })),
onSuccess: () => httpApp,
}),
),
),
)
I want to make a rate limiting middleware (ideally targeting specific HTTP routes).
I've looked at the code for the middlewares logging, tracing,... etc.
I've made an attempt, but it is hard to wrap my brain around
platform
.Here is an example of an
expess
middleware that works with express.But in platform.Http we don't have access to the response and next object. And it does not look like there is the IP-number in the request.
Thanks for the good work @tim-smart