Is it possible to attach an extra handler (page hit counter) to fs::FileServeer
?
#2664
-
I am serving a couple of WASM applications and I'd like to keep track of visitor count requesting the binaries without writing out a bunch of extera routes for them manually. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
The easiest, cleanest approach is likely writing a fairing. You can either store hit counts when a request is received or wait for a successful response. Either case allows you to inspect the the content-type of the request so you record only hits for wasm binaries. The latter lets you check the response as well, so you could filter based on status or body type. In either case, it's only a few lines of code, especially if you use Give it a try. Take a look at the fairings example for inspiration, which actually implements a hit counter itself. |
Beta Was this translation helpful? Give feedback.
Ah, I can use
Request::guard
method. Would probably best ifFairing
docs mentioned a word about this though.