-- | Stolen from rack:-- Rack::URLMap takes a hash mapping urls or paths to apps, and-- dispatches accordingly. ---- URLMap modifies the SCRIPT_NAME and PATH_INFO such that the part-- relevant for dispatch is in the SCRIPT_NAME, and the rest in the-- PATH_INFO. This should be taken care of when you need to-- reconstruct the URL in order to create links.-- -- URLMap dispatches in such a way that the longest paths are tried-- first, since they are most specific.moduleHack2.Contrib.Middleware.URLMap(url_map)whereimportHack2importHack2.Contrib.UtilsimportData.List(find,isPrefixOf)importAir.Envhiding(Default,def)importPrelude()importqualifiedData.ByteString.Char8asBtypeRoutePath=(B.ByteString,Application)url_map::[RoutePath]->Middlewareurl_maphapp=\env->letpath=env.path_infoscript=env.script_namemod_envlocation=env{scriptName=script+location,pathInfo=path.B.drop(location.B.length)}incaseh.find(fst>(`B.isPrefixOf`path))ofNothing->appenvJust(location,app')->app'(mod_envlocation)