feat: Add visit counter with geolocation #3
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit introduces a feature to track visits for each redirected domain, including geolocation information based on the visitor's IP address.
A SQLite database (
stats.db) is used to persistently store visit data. Each visit records the URL, a timestamp, and the visitor's country and city.The geolocation is performed by calling the
ip-api.comexternal service. While a local database like GeoLite2 was initially considered, the external API is simpler to integrate for this project's scale.A new API endpoint
/statsis added to expose the collected data. It returns a JSON response with the total number of visits, a breakdown by URL, and for each URL, a breakdown by country. It also includes a simple metric for "unique users today," which is based on a count of distinct cities.The previous in-memory visit counter has been removed. A
.gitignorefile has also been added to exclude build artifacts and the database file from version control.