Add base web app

This commit is contained in:
2025-11-04 18:58:41 +01:00
parent 1cdd3d9e60
commit d05747e60e
21 changed files with 1511 additions and 181 deletions

View File

@@ -19,6 +19,21 @@ dependencies = [
"tracing",
]
[[package]]
name = "actix-cors"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "daa239b93927be1ff123eebada5a3ff23e89f0124ccb8609234e5103d5a5ae6d"
dependencies = [
"actix-utils",
"actix-web",
"derive_more",
"futures-util",
"log",
"once_cell",
"smallvec",
]
[[package]]
name = "actix-http"
version = "3.11.2"
@@ -1605,6 +1620,7 @@ dependencies = [
name = "matrixgw_backend"
version = "0.1.0"
dependencies = [
"actix-cors",
"actix-remote-ip",
"actix-session",
"actix-web",

View File

@@ -14,6 +14,7 @@ tokio = { version = "1.48.0", features = ["full"] }
actix-web = "4.11.0"
actix-session = { version = "0.11.0", features = ["redis-session"] }
actix-remote-ip = "0.1.0"
actix-cors = "0.7.1"
light-openid = "1.0.4"
bytes = "1.10.1"
sha2 = "0.10.9"

View File

@@ -3,10 +3,10 @@ use jwt_simple::algorithms::HS256Key;
use jwt_simple::prelude::{Clock, Duration, JWTClaims, MACLike};
use matrixgw_backend::constants;
use matrixgw_backend::extractors::auth_extractor::TokenClaims;
use matrixgw_backend::utils::rand_utils::rand_string;
use std::ops::Add;
use std::os::unix::prelude::CommandExt;
use std::process::Command;
use matrixgw_backend::utils::rand_utils::rand_string;
/// cURL wrapper to query MatrixGW
#[derive(Parser, Debug)]

View File

@@ -1,10 +1,13 @@
use actix_cors::Cors;
use actix_remote_ip::RemoteIPConfig;
use actix_session::SessionMiddleware;
use actix_session::config::SessionLifecycle;
use actix_session::storage::RedisSessionStore;
use actix_web::cookie::Key;
use actix_web::middleware::Logger;
use actix_web::{App, HttpServer, web};
use matrixgw_backend::app_config::AppConfig;
use matrixgw_backend::constants;
use matrixgw_backend::controllers::{auth_controller, server_controller};
use matrixgw_backend::users::User;
@@ -32,13 +35,23 @@ async fn main() -> std::io::Result<()> {
);
HttpServer::new(move || {
let session_mw = SessionMiddleware::builder(redis_store.clone(), secret_key.clone())
.cookie_name("matrixgw-session".to_string())
.session_lifecycle(SessionLifecycle::BrowserSession(Default::default()))
.build();
let cors = Cors::default()
.allowed_origin(&AppConfig::get().website_origin)
.allowed_methods(vec!["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"])
.allowed_header(constants::API_AUTH_HEADER)
.allow_any_header()
.supports_credentials()
.max_age(3600);
App::new()
.wrap(
SessionMiddleware::builder(redis_store.clone(), secret_key.clone())
.cookie_name("matrixgw-session".to_string())
.session_lifecycle(SessionLifecycle::BrowserSession(Default::default()))
.build(),
)
.wrap(Logger::default())
.wrap(session_mw)
.wrap(cors)
.app_data(web::Data::new(RemoteIPConfig {
proxy: AppConfig::get().proxy_ip.clone(),
}))