Skip to content

Commit

Permalink
Configurable catchall on xrpc-server (#2384)
Browse files Browse the repository at this point in the history
* allow configurable catchall on xrpc-server

* changeset
  • Loading branch information
dholms authored Apr 4, 2024
1 parent 115df69 commit cd4fcc7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/lovely-parrots-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@atproto/xrpc-server': patch
---

Add configurable catchall
5 changes: 4 additions & 1 deletion packages/xrpc-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ export class Server {
this.addLexicons(lexicons)
}
this.router.use(this.routes)
this.router.use('/xrpc/:methodId', this.catchall.bind(this))
this.router.use(
'/xrpc/:methodId',
opts?.catchall ?? this.catchall.bind(this),
)
this.router.use(errorMiddleware)
this.router.once('mount', (app: Application) => {
this.enableStreamingOnListen(app)
Expand Down
7 changes: 7 additions & 0 deletions packages/xrpc-server/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@ import {
ResponseTypeNames,
} from '@atproto/xrpc'

export type CatchallHandler = (
req: express.Request,
_res: express.Response,
next: express.NextFunction,
) => unknown

export type Options = {
validateResponse?: boolean
catchall?: CatchallHandler
payload?: {
jsonLimit?: number
blobLimit?: number
Expand Down

0 comments on commit cd4fcc7

Please sign in to comment.