model: intro `MModule::first_real_mmodule` to get the first non-fictive module
[nit.git] / lib / nitcorn / server_config.nit
index 2decb16..c2bd614 100644 (file)
@@ -21,10 +21,11 @@ module server_config
 
 # Server instance configuration
 class ServerConfig
-       # Virtual hosts list
+       # `VirtualHost`s served by this server
        var virtual_hosts = new VirtualHosts(self)
 
-       # TODO implement serialization or something like that
+       # Default `VirtualHost` to respond to requests not handled by any of the `virtual_hosts`
+       var default_virtual_host: nullable VirtualHost = null
 end
 
 # A `VirtualHost` configuration
@@ -39,8 +40,7 @@ class VirtualHost
        var routes = new Routes(self)
 
        # Create a virtual host from interfaces as strings
-       init(interfaces: String ...)
-       do
+       init(interfaces: String ...) is old_style_init do
                for i in interfaces do self.interfaces.add_from_string i
        end
 end
@@ -114,18 +114,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