Skip to content

Commit

Permalink
get rate limit ip correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
dholms committed Sep 11, 2023
1 parent b3046c3 commit 69b7753
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 7 deletions.
1 change: 1 addition & 0 deletions packages/pds/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export class PDS {
)

const app = express()
app.set('trust proxy', true)
app.use(cors())
app.use(loggerMiddleware)
app.use(compression())
Expand Down
2 changes: 1 addition & 1 deletion packages/xrpc-server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ export * from './stream'
export * from './rate-limiter'

export type { ServerTiming } from './util'
export { getReqIp, serverTimingHeader, ServerTimer } from './util'
export { serverTimingHeader, ServerTimer } from './util'
3 changes: 1 addition & 2 deletions packages/xrpc-server/src/rate-limiter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
RateLimiterStatus,
XRPCReqContext,
} from './types'
import { getReqIp } from './util'

export type RateLimiterOpts = {
keyPrefix: string
Expand Down Expand Up @@ -155,5 +154,5 @@ export const getTightestLimit = (
return lowest
}

const defaultKey: CalcKeyFn = (ctx: XRPCReqContext) => getReqIp(ctx.req)
const defaultKey: CalcKeyFn = (ctx: XRPCReqContext) => ctx.req.ip
const defaultPoints: CalcPointsFn = () => 1
4 changes: 0 additions & 4 deletions packages/xrpc-server/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,6 @@ function decodeBodyStream(
return stream
}

export const getReqIp = (req: express.Request): string => {
return req.ips.at(-1) ?? req.ip
}

export function serverTimingHeader(timings: ServerTiming[]) {
return timings
.map((timing) => {
Expand Down

0 comments on commit 69b7753

Please sign in to comment.