server.on -> loop

Seems that I can't put a loop in server.on

Sure you can. You should NOT be defining loop() in the body of the lambda expression, though. You can use ANY kind of looping construct, though.