| 
									
										
										
										
											2015-10-01 00:30:16 +02:00
										 |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Module dependencies | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Public node modules.
 | 
					
						
							|  |  |  | const _ = require('lodash'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Detect HTTP verb in an expression. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @api private | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-11 13:03:35 +02:00
										 |  |  | exports.detectRoute = endpoint => { | 
					
						
							| 
									
										
										
										
											2015-10-01 00:30:16 +02:00
										 |  |  |   const verbExpr = /^(all|get|post|put|delete|trace|options|connect|patch|head|redirect)\s+/i; | 
					
						
							|  |  |  |   let verb = _.last(endpoint.match(verbExpr) || []) || ''; | 
					
						
							|  |  |  |   verb = verb.toLowerCase(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // If a verb was specified, eliminate the verb from the original string.
 | 
					
						
							|  |  |  |   if (verb) { | 
					
						
							|  |  |  |     endpoint = endpoint.replace(verbExpr, ''); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Return the verb and the endpoint.
 | 
					
						
							|  |  |  |   return { | 
					
						
							| 
									
										
										
										
											2016-11-07 16:31:34 +01:00
										 |  |  |     verb, | 
					
						
							|  |  |  |     endpoint | 
					
						
							| 
									
										
										
										
											2015-10-01 00:30:16 +02:00
										 |  |  |   }; | 
					
						
							|  |  |  | }; |