@@ -115,14 +115,21 @@ class Route {
115115 return this . method ( [ 'DELETE' ] , ...middleware ) ;
116116 }
117117
118+ /**
119+ * Register a handler function for OPTIONS requests to this route
120+ */
121+ async options ( ...middleware : HttpMiddleware [ ] ) : Promise < void > {
122+ return this . method ( [ 'OPTIONS' ] , ...middleware ) ;
123+ }
124+
118125 /**
119126 * Register a handler function for GET, POST, PATCH, PUT and DELETE requests to this route.
120127 *
121128 * Most useful when routing isn't important or you're doing you own internal routing.
122129 */
123130 async all ( ...middleware : HttpMiddleware [ ] ) : Promise < void > {
124131 return this . method (
125- [ 'GET' , 'POST' , 'PATCH' , 'PUT' , 'DELETE' ] ,
132+ [ 'GET' , 'POST' , 'PATCH' , 'PUT' , 'DELETE' , 'OPTIONS' ] ,
126133 ...middleware
127134 ) ;
128135 }
@@ -246,6 +253,17 @@ class Api {
246253 const r = this . route ( match ) ;
247254 return r . delete ( ...middleware ) ;
248255 }
256+
257+ /**
258+ * Registers a new route with a OPTIONS handler in a single method.
259+ * @param match the route path matcher e.g. '/home'. Supports path params via colon prefix e.g. '/customers/:customerId'
260+ * @param middleware the middleware/handler to register for calls to DELETE
261+ * @returns {Promise } that resolves when the handler terminates.
262+ */
263+ async options ( match : string , ...middleware : HttpMiddleware [ ] ) : Promise < void > {
264+ const r = this . route ( match ) ;
265+ return r . options ( ...middleware ) ;
266+ }
249267}
250268
251269/**
0 commit comments