hitman/README.md

31 lines
1.2 KiB
Markdown

# Hitman counts your hits, man.
This is a simple webpage hit/visit counter service. To run in development, copy the provided `env.example` file
to `.env`. By default, it will look for a database file in your home directory called
`.hitman.db`. You can let hitman create it for you, or you can use the `sqlx db create` command (get
by running `cargo install sqlx-cli`; see https://crates.io/crates/sqlx-cli ); if you do that, don't
forget to also run `sqlx migrate run`, to create the tables. This project uses SQLx's compile-time
SQL checking macros, so your DB needs to have the tables to allow the SQL checks to work.
## How does it work?
If you wish to use this on your webpage, you need to add a couple lines. First, a "tracking pixel"
that registers the current page's view:
``` html
<img src=http://localhost:5000/hit style="visibility:hidden">
```
Then, some javascript to retrieve the hit counts:
``` html
help I don't know how to javascript, we need to get http://localhost:5000/hits/all (or 'day' or
'week'), and that will return the number of recorded hits for this page for that time period.
```
It uses the `referer` header to get the page it was called from, and uses that as the key for
counting the hit.