# See the License for the specific language governing permissions and
# limitations under the License.
+module example_advanced_logger is example
+
import popcorn
import realtime
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)