Compare commits
3 Commits
772bda8e93
...
6a31c89f53
Author | SHA1 | Date |
---|---|---|
Zynh Ludwig | 6a31c89f53 | |
Zynh Ludwig | 9b6445ec84 | |
Zynh Ludwig | d866fa37a6 |
|
@ -0,0 +1,12 @@
|
||||||
|
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
|
||||||
|
|
||||||
|
pub fn init_tracing() {
|
||||||
|
// Set up logging
|
||||||
|
tracing_subscriber::registry()
|
||||||
|
.with(
|
||||||
|
tracing_subscriber::EnvFilter::try_from_default_env()
|
||||||
|
.unwrap_or_else(|_| "nyazoom=debug,tower_http=debug".into()),
|
||||||
|
)
|
||||||
|
.with(tracing_subscriber::fmt::layer())
|
||||||
|
.init();
|
||||||
|
}
|
46
src/main.rs
46
src/main.rs
|
@ -26,9 +26,8 @@ use tokio_util::{
|
||||||
|
|
||||||
use tower_http::{limit::RequestBodyLimitLayer, services::ServeDir, trace::TraceLayer};
|
use tower_http::{limit::RequestBodyLimitLayer, services::ServeDir, trace::TraceLayer};
|
||||||
|
|
||||||
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
|
|
||||||
|
|
||||||
mod cache;
|
mod cache;
|
||||||
|
mod logging;
|
||||||
mod nyazoom_headers;
|
mod nyazoom_headers;
|
||||||
pub mod ssr;
|
pub mod ssr;
|
||||||
mod state;
|
mod state;
|
||||||
|
@ -41,24 +40,9 @@ use state::{AppState, UploadRecord};
|
||||||
use crate::state::AsyncRemoveRecord;
|
use crate::state::AsyncRemoveRecord;
|
||||||
use crate::views::{DownloadLinkPage, HtmxPage, LinkView, Welcome};
|
use crate::views::{DownloadLinkPage, HtmxPage, LinkView, Welcome};
|
||||||
|
|
||||||
pub mod error {
|
|
||||||
use std::io::{Error, ErrorKind};
|
|
||||||
|
|
||||||
pub fn io_other(s: &str) -> Error {
|
|
||||||
Error::new(ErrorKind::Other, s)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> io::Result<()> {
|
async fn main() -> io::Result<()> {
|
||||||
// Set up logging
|
logging::init_tracing();
|
||||||
tracing_subscriber::registry()
|
|
||||||
.with(
|
|
||||||
tracing_subscriber::EnvFilter::try_from_default_env()
|
|
||||||
.unwrap_or_else(|_| "nyazoom=debug,tower_http=debug".into()),
|
|
||||||
)
|
|
||||||
.with(tracing_subscriber::fmt::layer())
|
|
||||||
.init();
|
|
||||||
|
|
||||||
// uses create_dir_all to create both .cache and serve inside it in one go
|
// uses create_dir_all to create both .cache and serve inside it in one go
|
||||||
util::make_dir(".cache/serve").await?;
|
util::make_dir(".cache/serve").await?;
|
||||||
|
@ -85,17 +69,7 @@ async fn main() -> io::Result<()> {
|
||||||
.layer(TraceLayer::new_for_http())
|
.layer(TraceLayer::new_for_http())
|
||||||
.layer(middleware::from_fn(log_source));
|
.layer(middleware::from_fn(log_source));
|
||||||
|
|
||||||
// Server creation
|
serve(app).await;
|
||||||
let addr = SocketAddr::from(([0, 0, 0, 0], 3000));
|
|
||||||
let listener = tokio::net::TcpListener::bind(&addr).await.unwrap();
|
|
||||||
axum::serve(
|
|
||||||
listener,
|
|
||||||
app.into_make_service_with_connect_info::<SocketAddr>(),
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
tracing::debug!("listening on http://{}/", addr);
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -321,3 +295,17 @@ async fn download(
|
||||||
|
|
||||||
Ok(Redirect::to("/404.html").into_response())
|
Ok(Redirect::to("/404.html").into_response())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn serve(app: Router) {
|
||||||
|
// // Server creation
|
||||||
|
let addr = SocketAddr::from(([0, 0, 0, 0], 3000));
|
||||||
|
let listener = tokio::net::TcpListener::bind(&addr).await.unwrap();
|
||||||
|
axum::serve(
|
||||||
|
listener,
|
||||||
|
app.into_make_service_with_connect_info::<SocketAddr>(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
tracing::debug!("listening on http://{}/", addr);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue