@@ -302,12 +302,7 @@ export class Appservice extends EventEmitter {
302
302
this . app . post ( "/_matrix/app/v1/unstable/org.matrix.msc3984/keys/query" , this . onKeysQuery . bind ( this ) ) ;
303
303
this . app . post ( "/unstable/org.matrix.msc3984/keys/query" , this . onKeysQuery . bind ( this ) ) ;
304
304
305
- // Everything else should 404
306
- // Technically, according to https://spec.matrix.org/v1.6/application-service-api/#unknown-routes we should
307
- // be returning 405 for *known* endpoints with the wrong method.
308
- this . app . all ( "*" , ( req : express . Request , res : express . Response ) => {
309
- res . status ( 404 ) . json ( { errcode : "M_UNRECOGNIZED" , error : "Endpoint not implemented" } ) ;
310
- } ) ;
305
+ // We register the 404 handler in the `begin()` function to allow consumers to add their own endpoints.
311
306
312
307
if ( ! this . registration . namespaces || ! this . registration . namespaces . users || this . registration . namespaces . users . length === 0 ) {
313
308
throw new Error ( "No user namespaces in registration" ) ;
@@ -381,6 +376,13 @@ export class Appservice extends EventEmitter {
381
376
*/
382
377
public begin ( ) : Promise < void > {
383
378
return new Promise < void > ( ( resolve , reject ) => {
379
+ // Per constructor, all other endpoints should 404.
380
+ // Technically, according to https://spec.matrix.org/v1.6/application-service-api/#unknown-routes we should
381
+ // be returning 405 for *known* endpoints with the wrong method.
382
+ this . app . all ( "*" , ( req : express . Request , res : express . Response ) => {
383
+ res . status ( 404 ) . json ( { errcode : "M_UNRECOGNIZED" , error : "Endpoint not implemented" } ) ;
384
+ } ) ;
385
+
384
386
this . appServer = this . app . listen ( this . options . port , this . options . bindAddress , ( ) => resolve ( ) ) ;
385
387
} ) . then ( async ( ) => {
386
388
if ( this . options . intentOptions ?. encryption ) {
0 commit comments