X-Git-Url: http://nitlanguage.org diff --git a/lib/nitcorn/server_config.nit b/lib/nitcorn/server_config.nit index a2f2226..3cf51ff 100644 --- a/lib/nitcorn/server_config.nit +++ b/lib/nitcorn/server_config.nit @@ -25,7 +25,7 @@ class ServerConfig var virtual_hosts = new VirtualHosts(self) # Default `VirtualHost` to respond to requests not handled by any of the `virtual_hosts` - var default_virtual_host: nullable VirtualHost = null + var default_virtual_host: nullable VirtualHost = null is writable end # A `VirtualHost` configuration @@ -61,6 +61,12 @@ class Route # Path to this action present in the URI var path: nullable String + init + do + var path = path + if path != null then self.path = "/" / path + end + # `Action` to activate when this route is traveled var handler: Action end @@ -76,7 +82,7 @@ class Interfaces super Array[Interface] # Back reference to the associtated `VirtualHost` - var vh: VirtualHost + var virtual_host: VirtualHost # Add an `Interface` described by `text` formatted as `interface.name.com:port` fun add_from_string(text: String) @@ -114,18 +120,19 @@ class Routes # Back reference to the config of the virtual host var config: VirtualHost - private var array = new Array[Route] + # Internal routes array. + protected var routes = new Array[Route] # Add `e` to `self` - fun add(e: Route) do array.add e + fun add(e: Route) do routes.add e # Remove `e` from `self` - fun remove(e: Route) do array.remove e + fun remove(e: Route) do routes.remove e # Get the first `Route` than has `key` as prefix to its path fun [](key: String): nullable Route do - for route in array do + for route in routes do var path = route.path if path == null or key.has_prefix(path) then return route end