Debian Codegraph @

pretender/src/hosts.ts

raw
1 import Registry from './registry';
2 import parseURL from './parse-url';
3
4 /**
5 * Hosts
6 *
7 * a map of hosts to Registries, ultimately allowing
8 * a per-host-and-port, per HTTP verb lookup of RouteRecognizers
9 */
10 export default class Hosts {
11
12 private registries = {};
13
14 /**
15 * Hosts#forURL - retrieve a map of HTTP verbs to RouteRecognizers
16 * for a given URL
17 *
18 * @param {String} url a URL
19 * @return {Registry} a map of HTTP verbs to RouteRecognizers
20 * corresponding to the provided URL's
21 * hostname and port
22 */
23 forURL(url: string): Registry {
24 let host = parseURL(url).host;
25 let registry = this.registries[host];
26
27 if (registry === undefined) {
28 registry = (this.registries[host] = new Registry(/*host*/));
29 }
30
31 return registry.verbs;
32 }
33 }