diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7d92138 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +# Build stage +FROM rust:latest AS builder +WORKDIR /usr/src/app +COPY . . +RUN cargo build --release + +# Run stage +FROM debian:bookworm-slim +RUN apt-get update && apt-get install -y libssl3 ca-certificates && apt-get clean +COPY --from=builder /usr/src/app/Neighborhood_Map_Atlas_Neighborhoods.geojson / +COPY --from=builder /usr/src/app/map.html / +COPY --from=builder /usr/src/app/target/release/mapbattle /usr/local/bin/mapbattle +EXPOSE 8080 +CMD ["mapbattle"] \ No newline at end of file diff --git a/map.html b/map.html index a54d708..f5b04f3 100644 --- a/map.html +++ b/map.html @@ -5,23 +5,75 @@
+ \ No newline at end of file diff --git a/src/data.rs b/src/data.rs index ab6952b..76a8055 100644 --- a/src/data.rs +++ b/src/data.rs @@ -25,6 +25,12 @@ impl Team { } } +#[derive(Debug, Clone, Deserialize, Serialize)] +pub struct TeamLegend { + pub name: String, + pub color: String +} + #[cfg(test)] mod tests { use super::*; diff --git a/src/main.rs b/src/main.rs index 0d1f60a..1cbc234 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,7 @@ use chrono::NaiveDateTime; use reqwest::Client; use xml::reader::EventReader; use actix_web::{get, App, HttpResponse, HttpServer, Responder}; -use crate::data::{Team, Player}; +use crate::data::{Team, Player, TeamLegend}; use std::collections::HashMap; use std::fs::File; use std::io::BufWriter; @@ -20,6 +20,16 @@ use std::time::Duration; const DATE_FORMAT: &str = "%Y-%m-%dT%H:%M:%SZ"; +#[get("/legend-data")] +async fn legend_data() -> impl Responder { + let teams = read_scores(); + let legends: Vec = teams.into_iter() + .map(|t| TeamLegend{name: t.name, color: t.color}).collect(); + HttpResponse::Ok() + .content_type("application/json") + .body(serde_json::to_string(&legends).unwrap()) +} + #[get("/geojson")] async fn geojson_endpoint() -> impl Responder { let utils = geo_utils::GeoUtils::new(); @@ -51,8 +61,9 @@ async fn main() -> std::io::Result<()> { App::new() .service(index) .service(geojson_endpoint) + .service(legend_data) }) - .bind(("127.0.0.1", 8080))? + .bind(("0.0.0.0", 8080))? .run() .await }