nitlanguage
/
nit.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
lib/popcorn: extract Router::build_route private service
[nit.git]
/
lib
/
nitcorn
/
server_config.nit
diff --git
a/lib/nitcorn/server_config.nit
b/lib/nitcorn/server_config.nit
index
f90d4ef
..
e61caad
100644
(file)
--- a/
lib/nitcorn/server_config.nit
+++ b/
lib/nitcorn/server_config.nit
@@
-40,8
+40,7
@@
class VirtualHost
var routes = new Routes(self)
# Create a virtual host from interfaces as strings
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
for i in interfaces do self.interfaces.add_from_string i
end
end
@@
-62,6
+61,12
@@
class Route
# Path to this action present in the URI
var path: nullable String
# 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
# `Action` to activate when this route is traveled
var handler: Action
end
@@
-115,18
+120,19
@@
class Routes
# Back reference to the config of the virtual host
var config: VirtualHost
# 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`
# Add `e` to `self`
- fun add(e: Route) do array.add e
+ fun add(e: Route) do routes.add e
# Remove `e` from `self`
# 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
# 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
var path = route.path
if path == null or key.has_prefix(path) then return route
end