diff --git a/src/api/v1/servers/uuid/channels/uuid/mod.rs b/src/api/v1/servers/uuid/channels/uuid/mod.rs index 277052c..81b4dfc 100644 --- a/src/api/v1/servers/uuid/channels/uuid/mod.rs +++ b/src/api/v1/servers/uuid/channels/uuid/mod.rs @@ -1,4 +1,5 @@ pub mod messages; +pub mod socket; use actix_web::{delete, get, web, Error, HttpRequest, HttpResponse}; use crate::{api::v1::auth::check_access_token, structs::{Channel, Member}, utils::get_auth_header, Data}; diff --git a/src/wss.rs b/src/api/v1/servers/uuid/channels/uuid/socket.rs similarity index 91% rename from src/wss.rs rename to src/api/v1/servers/uuid/channels/uuid/socket.rs index 9f33f10..64dcc44 100644 --- a/src/wss.rs +++ b/src/api/v1/servers/uuid/channels/uuid/socket.rs @@ -1,7 +1,8 @@ -use actix_web::{rt, web, Error, HttpRequest, HttpResponse}; +use actix_web::{get, rt, web, Error, HttpRequest, HttpResponse}; use actix_ws::AggregatedMessage; use futures_util::StreamExt as _; +#[get("{uuid}/channels/{channel_uuid}/socket")] pub async fn echo(req: HttpRequest, stream: web::Payload) -> Result { let (res, mut session, stream) = actix_ws::handle(&req, stream)?; @@ -37,4 +38,4 @@ pub async fn echo(req: HttpRequest, stream: web::Payload) -> Result Scope { .service(channels::uuid::get) .service(channels::uuid::delete) .service(channels::uuid::messages::get) + .service(channels::uuid::socket::echo) // Roles .service(roles::get) .service(roles::create) diff --git a/src/main.rs b/src/main.rs index a80ad0e..0ba2f69 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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(()) }