|
|
@ -2,7 +2,7 @@ type Pool = ::r2d2::Pool<::r2d2_sqlite::SqliteConnectionManager>;
|
|
|
|
pub type Connection = ::r2d2::PooledConnection<::r2d2_sqlite::SqliteConnectionManager>;
|
|
|
|
pub type Connection = ::r2d2::PooledConnection<::r2d2_sqlite::SqliteConnectionManager>;
|
|
|
|
|
|
|
|
|
|
|
|
fn initialize_db_pool() -> Pool {
|
|
|
|
fn initialize_db_pool() -> Pool {
|
|
|
|
let conn_spec = std::env::var("DATABASE_URL").expect("DATABASE_URL should be set");
|
|
|
|
let conn_spec = std::env::var("TILE_BASE_PATH").expect("TILE_BASE_PATH should be set");
|
|
|
|
let manager = ::r2d2_sqlite::SqliteConnectionManager::file(conn_spec);
|
|
|
|
let manager = ::r2d2_sqlite::SqliteConnectionManager::file(conn_spec);
|
|
|
|
Pool::new(manager).unwrap()
|
|
|
|
Pool::new(manager).unwrap()
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -43,7 +43,7 @@ async fn execute(
|
|
|
|
Ok(data)
|
|
|
|
Ok(data)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[::actix_web::get("/{z}/{x}/{y}.png")]
|
|
|
|
#[::actix_web::get("/tile/{z}/{x}/{y}.png")]
|
|
|
|
async fn get_tile(
|
|
|
|
async fn get_tile(
|
|
|
|
pool: ::actix_web::web::Data<Pool>,
|
|
|
|
pool: ::actix_web::web::Data<Pool>,
|
|
|
|
info: ::actix_web::web::Path<(u32, i64, i64)>,
|
|
|
|
info: ::actix_web::web::Path<(u32, i64, i64)>,
|
|
|
@ -68,6 +68,16 @@ async fn get_tile(
|
|
|
|
.body(data)
|
|
|
|
.body(data)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[::actix_web::get("/terrain/{tail:.*}")]
|
|
|
|
|
|
|
|
async fn get_terrain(
|
|
|
|
|
|
|
|
terrain: ::actix_web::web::Data<String>,
|
|
|
|
|
|
|
|
info: ::actix_web::web::Path<String>,
|
|
|
|
|
|
|
|
) -> impl ::actix_web::Responder {
|
|
|
|
|
|
|
|
let info = info.into_inner();
|
|
|
|
|
|
|
|
::log::info!("{}", terrain.to_string() + &info);
|
|
|
|
|
|
|
|
::actix_files::NamedFile::open(terrain.to_string() + &info)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[::actix_web::main]
|
|
|
|
#[::actix_web::main]
|
|
|
|
async fn main() -> std::io::Result<()> {
|
|
|
|
async fn main() -> std::io::Result<()> {
|
|
|
|
::dotenvy::dotenv().ok();
|
|
|
|
::dotenvy::dotenv().ok();
|
|
|
@ -76,6 +86,12 @@ async fn main() -> std::io::Result<()> {
|
|
|
|
|
|
|
|
|
|
|
|
let pool = initialize_db_pool();
|
|
|
|
let pool = initialize_db_pool();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let mut terrain = std::env::var("TERRAIN_BASE_PATH").expect("TERRAIN_BASE_PATH should be set");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if !terrain.ends_with("/") {
|
|
|
|
|
|
|
|
terrain.push('/');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
::log::info!("starting HTTP server at http://127.0.0.1:8080");
|
|
|
|
::log::info!("starting HTTP server at http://127.0.0.1:8080");
|
|
|
|
|
|
|
|
|
|
|
|
::actix_web::HttpServer::new(move || {
|
|
|
|
::actix_web::HttpServer::new(move || {
|
|
|
@ -96,7 +112,9 @@ async fn main() -> std::io::Result<()> {
|
|
|
|
.max_age(3600),
|
|
|
|
.max_age(3600),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.app_data(::actix_web::web::Data::new(pool.clone()))
|
|
|
|
.app_data(::actix_web::web::Data::new(pool.clone()))
|
|
|
|
|
|
|
|
.app_data(::actix_web::web::Data::new(terrain.clone()))
|
|
|
|
.service(get_tile)
|
|
|
|
.service(get_tile)
|
|
|
|
|
|
|
|
.service(get_terrain)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.bind(("127.0.0.1", 8080))?
|
|
|
|
.bind(("127.0.0.1", 8080))?
|
|
|
|
.workers(2)
|
|
|
|
.workers(2)
|
|
|
|