Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: copy static assets to correct workdir #9

Merged
merged 3 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ ARG APP_PORT
ARG DATABASE_PUBLIC_URL

RUN apt-get update \
&& apt-get install -y ca-certificates \
&& rm -rf /var/lib/apt/lists/*
&& apt-get install -y ca-certificates \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY static /usr/local/bin/static
COPY static /app/static
COPY --from=builder /app/target/release/spyhole /usr/local/bin/spyhole

ENV RUST_LOG=$RUST_LOG
Expand Down
14 changes: 4 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use axum::{
extract::State,
response::{Html, IntoResponse},
response::IntoResponse,
routing::{get, post},
Json, Router,
};
use chrono::{NaiveDate, Utc};
use serde::{Deserialize, Serialize};
use sqlx::{postgres::PgPoolOptions, PgPool};
use std::env;
use tokio::time::{sleep, Duration};
use tower::ServiceBuilder;
use tower_http::{services::ServeDir, trace::TraceLayer};
Expand Down Expand Up @@ -120,10 +119,6 @@ async fn get_monitored_urls(State(pool): State<PgPool>) -> impl IntoResponse {
response_html.into_response()
}

async fn index() -> Html<&'static str> {
Html(include_str!("../static/index.html"))
}

#[tokio::main]
async fn main() {
dotenvy::dotenv().ok();
Expand All @@ -134,7 +129,7 @@ async fn main() {

tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed");

let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set");
let database_url = std::env::var("DATABASE_URL").expect("DATABASE_URL must be set");
let pool = PgPoolOptions::new()
.max_connections(5)
.connect(&database_url)
Expand All @@ -151,14 +146,13 @@ async fn main() {
}

let app = Router::new()
.route("/", get(index))
.nest_service("/assets", ServeDir::new("./static/assets"))
.nest_service("/", ServeDir::new("static"))
.route("/monitor", post(monitor_service))
.route("/monitored_urls", get(get_monitored_urls))
.layer(ServiceBuilder::new().layer(TraceLayer::new_for_http()))
.with_state(pool);

let port = env::var("APP_PORT").unwrap_or_else(|_| "5000".to_string());
let port = std::env::var("APP_PORT").unwrap_or_else(|_| "5000".to_string());
let addr = format!("0.0.0.0:{}", port);
let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
axum::serve(listener, app).await.unwrap();
Expand Down