diff --git a/Cargo.lock b/Cargo.lock index 8475a92..fb866cf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1491,6 +1491,8 @@ name = "fedimint-nwc" version = "0.3.5" dependencies = [ "anyhow", + "axum", + "axum-macros", "bincode", "clap 4.5.4", "dotenv", @@ -1504,6 +1506,7 @@ dependencies = [ "serde", "serde_json", "tokio", + "tower-http", "tracing", "tracing-subscriber", ] @@ -2018,6 +2021,12 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "http-range-header" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ce4ef31cda248bbdb6e6820603b82dfcd9e833db65a43e997a0ccec777d11fe" + [[package]] name = "httparse" version = "1.8.0" @@ -2639,6 +2648,16 @@ version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" +[[package]] +name = "mime_guess" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef" +dependencies = [ + "mime", + "unicase", +] + [[package]] name = "minimal-lexical" version = "0.2.1" @@ -4266,11 +4285,18 @@ dependencies = [ "base64 0.21.7", "bitflags 2.5.0", "bytes", + "futures-util", "http 1.1.0", "http-body 1.0.0", "http-body-util", + "http-range-header", + "httpdate", "mime", + "mime_guess", + "percent-encoding", "pin-project-lite", + "tokio", + "tokio-util", "tower-layer", "tower-service", "tracing", @@ -4383,6 +4409,15 @@ version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" +[[package]] +name = "unicase" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" +dependencies = [ + "version_check", +] + [[package]] name = "unicode-bidi" version = "0.3.15" diff --git a/fedimint-nwc/Cargo.toml b/fedimint-nwc/Cargo.toml index a4bbd4a..2e1c779 100644 --- a/fedimint-nwc/Cargo.toml +++ b/fedimint-nwc/Cargo.toml @@ -10,6 +10,8 @@ authors.workspace = true [dependencies] anyhow = "1.0.75" +axum = { version = "0.7.1", features = ["json"] } +axum-macros = "0.4.0" bincode = "1.3.3" clap = { version = "4.5.4", features = ["derive", "env"] } dotenv = "0.15.0" @@ -24,5 +26,6 @@ redb = "2.1.0" serde = "1.0.193" serde_json = "1.0.108" tokio = { version = "1.34.0", features = ["full"] } +tower-http = { version = "0.5.2", features = ["fs"] } tracing = "0.1.40" tracing-subscriber = "0.3.18" diff --git a/fedimint-nwc/frontend/assets/index.html b/fedimint-nwc/frontend/assets/index.html new file mode 100644 index 0000000..4f98b1f --- /dev/null +++ b/fedimint-nwc/frontend/assets/index.html @@ -0,0 +1,69 @@ + + + + + + Sample HTML Document + + + +
+

Welcome to My Website

+ +
+
+

Home

+

This is a sample HTML document to demonstrate the basic structure of an HTML page. You can use this as a starting point for your own web projects.

+

About

+

Learn more about the purpose of this website and the content it provides.

+

Contact

+

If you have any questions or comments, feel free to reach out through the contact form.

+
+ + + diff --git a/fedimint-nwc/frontend/assets/script.js b/fedimint-nwc/frontend/assets/script.js new file mode 100644 index 0000000..e69de29 diff --git a/fedimint-nwc/src/main.rs b/fedimint-nwc/src/main.rs index ee6b852..ddf3ffc 100644 --- a/fedimint-nwc/src/main.rs +++ b/fedimint-nwc/src/main.rs @@ -1,16 +1,18 @@ use anyhow::Result; use clap::Parser; use nostr_sdk::{JsonUtil, Kind, RelayPoolNotification}; -use tokio::pin; +use tokio::{pin, task}; use tracing::{error, info}; pub mod config; pub mod database; pub mod nwc; pub mod services; -pub mod state; +pub mod state; +use axum::Router; use state::AppState; +use tower_http::services::ServeDir; use crate::config::Cli; @@ -28,6 +30,17 @@ async fn main() -> Result<()> { state.nostr_service.connect().await; state.nostr_service.broadcast_info_event().await?; + let server = Router::new().nest_service("/", ServeDir::new("frontend/assets")); + let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap(); + + // Spawn a new Tokio task for the server + let server_task = task::spawn(async move { + axum::serve(listener, server).await.unwrap(); + }); + + // Wait for the server task to complete if necessary + server_task.await?; + // Start the event loop event_loop(state.clone()).await?;