ProductOpener::Routing - determines which page to display or API to call based on the URL path
Load OFF routes
a route is registered with: - Pattern: - a simple string (e.g. "api") without '/'': when you simply want to route with the first component of the path e.g. product/1234 -> product_route No regex is involved. It uses a hash key
- Or a pattern that capture arguments (e.g. "org/[orgid]"): - The value of the orgid param will be stored in $request_ref->{param}{orgid} - Ending the pattern with a / means that it can be followed by anything ! Mind the priority of the routes, the first one that matches will be used - Handler (sub) - (optional) Options : { - name - regex: 1 if the pattern is a true regex, 0 by default. When you don't want to use the default limited one. Use named captures to store the arguments in $request_ref->{param} - onlyif: a sub($request_ref) that will be called to check if the route should be used Its a dynamic routing, using context of the request. Results is used as a boolean to decide if the route should be used. }
non regex routes will be matched first, then regex routes
Analyze request parameters and decide which method to call.
It will analyze path and parameters.
Some information is set in request_ref, notably - polished query_string - page number (page) - api version (e.g v3), api action (e.g product) and api method (e.g. GET or POST) - requested page (text) - some boolean for routing : search / taxonomy / mission / product / tag / points - parameters for products, mission, tags, etc.
It handles redirect for renamed texts or products, .well-known/change-password
Sometimes we modify request parameters (param) to correspond to request_ref: - parameters for response format : json, jsonp, xml, ... - code parameter
Register routes in the routes hash and regex_routes array.
Array of arrays.
Each array should contain 3 elements: - the pattern - the route handler (sub) - (optional) options { - route_name - regex: if present then the pattern is considered as a true regex pattern and the default and limited one won't be used }
Match a route based on the components of the request. non regex routes are matched first, then regex routes
Extract tag type / tag value pairs and store them in an array $request_ref->{tags}
e.g. /category/breakfast-cereals/label/organic/brand/monoprix
Tags can be prefixed by a - to indicate that we want products without this tag
Return 1 if the page should not be indexed by web crawlers based on analyzed request, 0 otherwise.
Set attributes related to rate-limiting in the request object:
- rate_limiter_user_requests: the number of requests performed by the user for the current minute - rate_limiter_limit: the maximum number of requests allowed for the current minute - rate_limiter_blocking: 1 if the user has reached the rate-limit, 0 otherwise