examples: annotate examples
[nit.git] / lib / popcorn / examples / middlewares / example_advanced_logger.nit
index b97d10c..d77725f 100644 (file)
@@ -14,6 +14,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+module example_advanced_logger is example
+
 import popcorn
 import realtime
 
@@ -28,27 +30,27 @@ class RequestTimeHandler
        redef fun all(req, res) do req.timer = new Clock
 end
 
-class LogHandler
+class AdvancedLoggerHandler
        super Handler
 
        redef fun all(req, res) do
                var timer = req.timer
                if timer != null then
-                       print "{req.method} {req.uri} {res.color_status} ({timer.total})"
+                       print "{req.method} {req.uri} {res.color_status} ({timer.total}s)"
                else
                        print "{req.method} {req.uri} {res.color_status}"
                end
        end
 end
 
-class HelloHandler
+class AnotherHandler
        super Handler
 
        redef fun get(req, res) do res.send "Hello World!"
 end
 
 var app = new App
-app.use("/*", new RequestTimeHandler)
-app.use("/", new HelloHandler)
-app.use("/*", new LogHandler)
+app.use_before("/*", new RequestTimeHandler)
+app.use("/", new AnotherHandler)
+app.use_after("/*", new AdvancedLoggerHandler)
 app.listen("localhost", 3000)