fullstack: added profile pictures/avatars to accounts and improved settings page layout
This commit is contained in:
36
src/main.rs
36
src/main.rs
@@ -1,14 +1,15 @@
|
||||
use axum::{
|
||||
Extension, Router,
|
||||
Extension,
|
||||
Router,
|
||||
http::{
|
||||
Method,
|
||||
header::{self, CONTENT_TYPE},
|
||||
},
|
||||
middleware,
|
||||
// middleware,
|
||||
};
|
||||
use axum::{body::Body, extract::Request, middleware::Next, response::Response};
|
||||
use clap::Parser;
|
||||
use std::{net::SocketAddr, time::Duration};
|
||||
use std::{net::SocketAddr, path::PathBuf, sync::Arc, time::Duration};
|
||||
use tower_governor::{GovernorLayer, governor::GovernorConfigBuilder};
|
||||
use tower_http::{
|
||||
cors::{Any, CorsLayer},
|
||||
@@ -22,6 +23,10 @@ mod db;
|
||||
mod realtime;
|
||||
mod routes;
|
||||
|
||||
pub struct AppConfig {
|
||||
pub avatar_dir: PathBuf,
|
||||
}
|
||||
|
||||
#[derive(clap::Parser, Debug)]
|
||||
#[command(author, version, about, long_about = None)]
|
||||
pub struct Cli {
|
||||
@@ -33,6 +38,10 @@ pub struct Cli {
|
||||
#[arg(short, long, default_value = "localhost:5432")]
|
||||
database: String,
|
||||
|
||||
/// Data directory path
|
||||
#[arg(short = 'D', long, default_value = "/var/lib/chatapp")]
|
||||
data_dir: String,
|
||||
|
||||
/// Verbose mode
|
||||
#[arg(short, long)]
|
||||
verbose: bool,
|
||||
@@ -74,6 +83,11 @@ async fn main() -> anyhow::Result<()> {
|
||||
|
||||
let realtime = realtime::Realtime::new();
|
||||
|
||||
let data_dir = PathBuf::from(cli.data_dir);
|
||||
let config = Arc::new(AppConfig {
|
||||
avatar_dir: data_dir.join("avatars"),
|
||||
});
|
||||
|
||||
let mut app = Router::new()
|
||||
.merge(routes::users::routes())
|
||||
.merge(routes::rooms::routes())
|
||||
@@ -82,17 +96,17 @@ async fn main() -> anyhow::Result<()> {
|
||||
.merge(routes::ws::routes())
|
||||
.layer(Extension(db_pool))
|
||||
.layer(Extension(realtime))
|
||||
.layer(Extension(config))
|
||||
.layer(GovernorLayer::new(governor_conf))
|
||||
.layer(cors);
|
||||
|
||||
if cli.verbose {
|
||||
app = app
|
||||
.layer(
|
||||
TraceLayer::new_for_http()
|
||||
.make_span_with(DefaultMakeSpan::new().level(Level::INFO))
|
||||
.on_response(DefaultOnResponse::new().level(Level::INFO)),
|
||||
)
|
||||
.layer(middleware::from_fn(log_json_body));
|
||||
app = app.layer(
|
||||
TraceLayer::new_for_http()
|
||||
.make_span_with(DefaultMakeSpan::new().level(Level::INFO))
|
||||
.on_response(DefaultOnResponse::new().level(Level::INFO)),
|
||||
)
|
||||
// .layer(middleware::from_fn(log_json_body));
|
||||
}
|
||||
|
||||
let port = cli.port;
|
||||
@@ -111,7 +125,7 @@ async fn main() -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn log_json_body(req: Request, next: Next) -> Response {
|
||||
async fn _log_json_body(req: Request, next: Next) -> Response {
|
||||
let (parts, body) = req.into_parts();
|
||||
|
||||
// Check if the content type is JSON
|
||||
|
||||
Reference in New Issue
Block a user