refactor: use project-local data/ directory for MMDB in local dev

This commit is contained in:
NetworkCats
2026-03-02 20:49:03 +08:00
parent bfc1e213b9
commit de5e4df9b3
3 changed files with 8 additions and 6 deletions
+2 -2
View File
@@ -1,8 +1,8 @@
# Server listen address
LISTEN_ADDR=0.0.0.0:3000
# Path to the MaxMind DB file
DB_PATH=/data/Merged-IP.mmdb
# Path to the MaxMind DB file (use data/Merged-IP.mmdb for local development)
DB_PATH=data/Merged-IP.mmdb
# URL to download the MMDB database from
DB_UPDATE_URL=https://github.com/NetworkCats/Merged-IP-Data/releases/latest/download/Merged-IP.mmdb
+1
View File
@@ -23,6 +23,7 @@ ehthumbs_vista.db
# Project
*.mmdb
data/
.env
haproxy/certs/
+5 -4
View File
@@ -8,16 +8,17 @@ use rustyip::db;
use rustyip::handlers::AppState;
use rustyip::routes::build_router;
fn test_db_path() -> &'static str {
let path = "/tmp/Merged-IP.mmdb";
if !Path::new(path).exists() {
fn test_db_path() -> String {
let manifest_dir = env!("CARGO_MANIFEST_DIR");
let path = format!("{manifest_dir}/data/Merged-IP.mmdb");
if !Path::new(&path).exists() {
panic!("Test MMDB not found at {path}. Download it first.");
}
path
}
fn build_test_app() -> axum::Router {
let reader = db::load_db(Path::new(test_db_path())).expect("failed to load test DB");
let reader = db::load_db(Path::new(&test_db_path())).expect("failed to load test DB");
let shared_db = db::new_shared(reader);
let state = AppState {
db: shared_db,