Switch to async-fred-session, default config vals
Fixup some issues in README too
This commit is contained in:
@@ -33,21 +33,23 @@ impl FromStr for IpSource {
|
||||
pub struct Config {
|
||||
#[clap(long, env)]
|
||||
pub database_url: String,
|
||||
#[clap(long, env)]
|
||||
#[clap(long, env, default_value = "5")]
|
||||
pub database_max_connections: u32,
|
||||
#[clap(long, env)]
|
||||
#[clap(long, env, default_value = "redis://localhost")]
|
||||
pub redis_url: String,
|
||||
#[clap(long, env)]
|
||||
#[clap(long, env, default_value = "5")]
|
||||
pub redis_pool_size: usize,
|
||||
#[clap(long, env, default_value = "127.0.0.1")]
|
||||
pub host: String,
|
||||
#[clap(long, env)]
|
||||
#[clap(long, env, default_value = "3000")]
|
||||
pub port: u16,
|
||||
#[clap(long, env)]
|
||||
#[clap(long, env, default_value = "http://localhost:3000")]
|
||||
pub public_url: Url,
|
||||
#[clap(long, env)]
|
||||
#[clap(long, env, default_value = "crawlnicle")]
|
||||
pub title: String,
|
||||
#[clap(long, env)]
|
||||
#[clap(long, env, default_value = "1000000")]
|
||||
pub max_mem_log_size: usize,
|
||||
#[clap(long, env)]
|
||||
#[clap(long, env, default_value = "./content")]
|
||||
pub content_dir: String,
|
||||
#[clap(long, env)]
|
||||
pub smtp_server: String,
|
||||
@@ -55,10 +57,10 @@ pub struct Config {
|
||||
pub smtp_user: String,
|
||||
#[clap(long, env)]
|
||||
pub smtp_password: String,
|
||||
#[clap(long, env)]
|
||||
#[clap(long, env, default_value = "crawlnicle <no-reply@mail.crawlnicle.com>")]
|
||||
pub email_from: Mailbox,
|
||||
#[clap(long, env)]
|
||||
pub session_secret: String,
|
||||
#[clap(long, env)]
|
||||
#[clap(long, env, default_value = "ConnectInfo")]
|
||||
pub ip_source: IpSource,
|
||||
}
|
||||
|
||||
11
src/main.rs
11
src/main.rs
@@ -1,7 +1,7 @@
|
||||
use std::{collections::HashMap, net::SocketAddr, path::Path, sync::Arc};
|
||||
|
||||
use anyhow::Result;
|
||||
use async_redis_session::RedisSessionStore;
|
||||
use async_fred_session::{RedisSessionStore, fred::{pool::RedisPool, types::RedisConfig}};
|
||||
use axum::{
|
||||
response::IntoResponse,
|
||||
routing::{get, post},
|
||||
@@ -72,11 +72,16 @@ async fn main() -> Result<()> {
|
||||
.connect(&config.database_url)
|
||||
.await?;
|
||||
|
||||
let session_store = RedisSessionStore::new(config.redis_url.clone())?;
|
||||
let redis_config = RedisConfig::from_url(&config.redis_url)?;
|
||||
let redis_pool = RedisPool::new(redis_config, None, None, config.redis_pool_size)?;
|
||||
redis_pool.connect();
|
||||
redis_pool.wait_for_connect().await?;
|
||||
|
||||
let session_store = RedisSessionStore::from_pool(redis_pool, Some("async-fred-session/".into()));
|
||||
let session_layer = SessionLayer::new(session_store, secret).with_secure(false);
|
||||
let user_store = PostgresStore::<User>::new(pool.clone())
|
||||
.with_query("select * from users where user_id = $1");
|
||||
let auth_layer = AuthLayer::new(user_store, &secret);
|
||||
let auth_layer = AuthLayer::new(user_store, secret);
|
||||
|
||||
let creds = Credentials::new(config.smtp_user.clone(), config.smtp_password.clone());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user