refactor: move websocket into existing webserver and folder structure

keeps things consistent and avoids having 2 webservers running under actix, can be reverted if its not desirable however i think this is the best option
This commit is contained in:
Radical 2025-05-15 11:57:47 +00:00
parent 79cfa25855
commit cb3c1ee6e4
4 changed files with 41 additions and 50 deletions

View file

@ -2,15 +2,12 @@ use actix_cors::Cors;
use actix_web::{web, App, HttpServer};
use argon2::Argon2;
use clap::Parser;
use futures::try_join;
use simple_logger::SimpleLogger;
use sqlx::{PgPool, Pool, Postgres};
use wss::echo;
use std::time::SystemTime;
mod config;
use config::{Config, ConfigBuilder};
mod api;
mod wss;
pub mod utils;
pub mod structs;
@ -173,51 +170,42 @@ async fn main() -> Result<(), Error> {
start_time: SystemTime::now(),
};
try_join!(
HttpServer::new(move || {
// Set CORS headers
let cors = Cors::default()
/*
Set Allowed-Control-Allow-Origin header to whatever
the request's Origin header is. Must be done like this
rather than setting it to "*" due to CORS not allowing
sending of credentials (cookies) with wildcard origin.
*/
.allowed_origin_fn(|_origin, _req_head| {
true
})
/*
Allows any request method in CORS preflight requests.
This will be restricted to only ones actually in use later.
*/
.allow_any_method()
/*
Allows any header(s) in request in CORS preflight requests.
This wll be restricted to only ones actually in use later.
*/
.allow_any_header()
/*
Allows browser to include cookies in requests.
This is needed for receiving the secure HttpOnly refresh_token cookie.
*/
.supports_credentials();
App::new()
.app_data(web::Data::new(data.clone()))
.wrap(cors)
.service(api::web())
})
.bind((web.url, web.port))?
.run(),
HttpServer::new(|| {
App::new()
.route("/servers/{server_id}/channels/{channel_id}",
web::get().to(echo))
})
.bind(("0.0.0.0", 4382))?
.run()
)?;
HttpServer::new(move || {
// Set CORS headers
let cors = Cors::default()
/*
Set Allowed-Control-Allow-Origin header to whatever
the request's Origin header is. Must be done like this
rather than setting it to "*" due to CORS not allowing
sending of credentials (cookies) with wildcard origin.
*/
.allowed_origin_fn(|_origin, _req_head| {
true
})
/*
Allows any request method in CORS preflight requests.
This will be restricted to only ones actually in use later.
*/
.allow_any_method()
/*
Allows any header(s) in request in CORS preflight requests.
This wll be restricted to only ones actually in use later.
*/
.allow_any_header()
/*
Allows browser to include cookies in requests.
This is needed for receiving the secure HttpOnly refresh_token cookie.
*/
.supports_credentials();
App::new()
.app_data(web::Data::new(data.clone()))
.wrap(cors)
.service(api::web())
})
.bind((web.url, web.port))?
.run()
.await?;
Ok(())
}