diff --git a/Cargo.lock b/Cargo.lock index 4383e03fa3..94b50f0ac9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2059,6 +2059,7 @@ dependencies = [ name = "http_server_common" version = "0.0.1" dependencies = [ + "actix-cors 0.5.4", "actix-cors 0.6.0-beta.3", "actix-http 2.2.0", "actix-http 3.0.0-beta.11", @@ -4048,7 +4049,6 @@ dependencies = [ "hex", "hmac 0.10.1", "hostname", - "http_server_common", "hyper 0.13.10", "infer", "jwt", diff --git a/app/http_server_common/Cargo.toml b/app/http_server_common/Cargo.toml index 8ac3c31bc8..545e3e3aa3 100644 --- a/app/http_server_common/Cargo.toml +++ b/app/http_server_common/Cargo.toml @@ -22,11 +22,13 @@ dotenv = "0.15.0" log = "0.4.14" # Web -actix-cors = "0.6.0-beta.3" # NB: One microservice requires old Tokio (thus old actix), and another new Tokio (new actix). # Thus I'm being extremely extra here and supporting both. +actix-cors-old = { package = "actix-cors", version = "0.5.4", optional = true } actix-http-old = { package = "actix-http", version = "2.2.0", optional = true } actix-web-old = { package = "actix-web", version = "3.3.2", optional = true } + +actix-cors-new = { package = "actix-cors", version = "0.6.0-beta.3", optional = true } actix-http-new = { package = "actix-http", version = "3.0.0-beta.11", optional = true } actix-web-new = { package = "actix-web", version = "4.0.0-beta.10", optional = true } @@ -37,5 +39,6 @@ serde_json = "1.0.64" toml = "0.5.8" [features] -actix-new = ["actix-http-new", "actix-web-new"] -actix-old = ["actix-http-old", "actix-web-old"] +# default = ["actix-cors-new", "actix-web-new", "actix-http-new"] +actix-new = ["actix-cors-new", "actix-http-new", "actix-web-new"] +actix-old = ["actix-cors-old", "actix-http-old", "actix-web-old"] diff --git a/app/http_server_common/src/endpoints/root_index.rs b/app/http_server_common/src/endpoints/root_index.rs index 415b514186..fe50b3a901 100644 --- a/app/http_server_common/src/endpoints/root_index.rs +++ b/app/http_server_common/src/endpoints/root_index.rs @@ -1,18 +1,11 @@ use actix_http::http::StatusCode; -use actix_web::{HttpResponse, HttpRequest, Responder, get}; +use actix_web::{HttpResponse, HttpRequest, get}; +use actix_web::Responder; +use actix_web::Result; +use actix_web::Error; use log::debug; - -/* -error[E0277]: the trait bound `fn() -> impl futures::Future {get_root_index}: HttpServiceFactory` is not satisfied - --> app/storyteller_web/src/main.rs:627:16 - | -627 | .service(get_root_index) - | ^^^^^^^^^^^^^^ the trait `HttpServiceFactory` is not implemented for `fn() -> impl futures::Future {get_root_index}` - */ - - -pub async fn get_root_index() -> impl Responder { +pub async fn get_root_index() -> HttpResponse { debug!("GET /"); // NB: Google load balancer hits this a lot, and it spams. HttpResponse::build(StatusCode::OK) .content_type("text/html; charset=utf-8") diff --git a/app/http_server_common/src/lib.rs b/app/http_server_common/src/lib.rs index 3285e4237f..a7e0cb7a41 100644 --- a/app/http_server_common/src/lib.rs +++ b/app/http_server_common/src/lib.rs @@ -10,16 +10,44 @@ // I don't think this will be too hard to maintain. AFAICT, the only major differences are which // package "HttpResponseBuilder" is located in. -#[cfg(feature = "actix-new")] +#[cfg(all(feature = "actix-new", not(feature = "actix-old")))] +//#[cfg(feature = "actix-cors-new")] +extern crate actix_cors_new as actix_cors; +#[cfg(all(feature = "actix-new", not(feature = "actix-old")))] +//#[cfg(feature = "actix-http-new")] extern crate actix_http_new as actix_http; -#[cfg(feature = "actix-new")] +#[cfg(all(feature = "actix-new", not(feature = "actix-old")))] +//#[cfg(feature = "actix-web-new")] extern crate actix_web_new as actix_web; -#[cfg(not(feature = "actix-new"))] +#[cfg(all(feature = "actix-old", not(feature = "actix-new")))] +//#[cfg(feature = "actix-cors-old")] +extern crate actix_cors_old as actix_cors; +#[cfg(all(feature = "actix-old", not(feature = "actix-new")))] +//#[cfg(feature = "actix-http-old")] extern crate actix_http_old as actix_http; -#[cfg(not(feature = "actix-new"))] +#[cfg(all(feature = "actix-old", not(feature = "actix-new")))] +//#[cfg(feature = "actix-web-old")] extern crate actix_web_old as actix_web; +//#[cfg(any( +// all(feature = "actix-cors-new", not(feature = "actix-cors-old")), +// all(feature = "actix-cors-old", not(feature = "actix-cors-new")), +//))] +#[cfg(any( + feature = "actix-new", + feature = "actix-old", +))] pub mod cors; + +#[cfg(any( + feature = "actix-new", + feature = "actix-old", +))] pub mod endpoints; + +#[cfg(any( + feature = "actix-new", + feature = "actix-old", +))] pub mod response; diff --git a/app/obs_gateway/src/main.rs b/app/obs_gateway/src/main.rs index a2485b7a3c..e69ece9f53 100644 --- a/app/obs_gateway/src/main.rs +++ b/app/obs_gateway/src/main.rs @@ -315,6 +315,9 @@ pub async fn serve(server_state: ObsGatewayServerState) -> AnyhowResult<()> .wrap(DefaultHeaders::new() .header("X-Backend-Hostname", &hostname) .header("X-Build-Sha", "")) + .service(web::resource("/") + .route(web::get().to(get_root_index)) + ) // Twitch .service( web::resource("/twitch") diff --git a/app/storyteller_web/Cargo.toml b/app/storyteller_web/Cargo.toml index cd9417bd22..a1e229c316 100644 --- a/app/storyteller_web/Cargo.toml +++ b/app/storyteller_web/Cargo.toml @@ -39,7 +39,7 @@ path = "src/w2l_inference_job.rs" # Internal config = { path = "../config" } -http_server_common = { path = "../http_server_common", features = ["actix-old"] } +#http_server_common = { path = "../http_server_common", features = ["actix-old"] } # External anyhow = "1.0.40" @@ -101,9 +101,6 @@ tempdir = "0.3.7" # Web actix = "0.10" -#actix-web = "3" -actix-web-actors = "3" - actix-cors = "0.5.4" actix-files= "0.5" actix-http = "2.2.0" @@ -112,6 +109,7 @@ actix-rt = "2.2.0" actix-service = "1.0.6" actix-utils = "3.0.0" actix-web = "3.3.2" +actix-web-actors = "3" jwt = "0.13.0" # NB: Hyper is just for HTTP client use in jobs. I'd use Actix client, but I need tokio runtime diff --git a/app/storyteller_web/src/http_server/endpoints/misc/default_route_404.rs b/app/storyteller_web/src/http_server/endpoints/misc/default_route_404.rs new file mode 100644 index 0000000000..6bc7403c15 --- /dev/null +++ b/app/storyteller_web/src/http_server/endpoints/misc/default_route_404.rs @@ -0,0 +1,10 @@ +use actix_http::http::StatusCode; +use actix_web::{HttpResponse, HttpRequest, Responder, get}; +use log::warn; + +pub async fn default_route_404() -> impl Responder { + warn!("404 not found"); + HttpResponse::NotFound() + .content_type("text/html; charset=utf-8") + .body("

not found

") +} diff --git a/app/storyteller_web/src/http_server/endpoints/misc/mod.rs b/app/storyteller_web/src/http_server/endpoints/misc/mod.rs index d5d7a2545d..c4da5e82d0 100644 --- a/app/storyteller_web/src/http_server/endpoints/misc/mod.rs +++ b/app/storyteller_web/src/http_server/endpoints/misc/mod.rs @@ -1,3 +1,5 @@ pub mod alpha_cookie; +pub mod default_route_404; +pub mod enable_alpha_easy_handler; pub mod enable_alpha_handler; -pub mod enable_alpha_easy_handler; \ No newline at end of file +pub mod root_index; \ No newline at end of file diff --git a/app/storyteller_web/src/http_server/endpoints/misc/root_index.rs b/app/storyteller_web/src/http_server/endpoints/misc/root_index.rs new file mode 100644 index 0000000000..fe50b3a901 --- /dev/null +++ b/app/storyteller_web/src/http_server/endpoints/misc/root_index.rs @@ -0,0 +1,13 @@ +use actix_http::http::StatusCode; +use actix_web::{HttpResponse, HttpRequest, get}; +use actix_web::Responder; +use actix_web::Result; +use actix_web::Error; +use log::debug; + +pub async fn get_root_index() -> HttpResponse { + debug!("GET /"); // NB: Google load balancer hits this a lot, and it spams. + HttpResponse::build(StatusCode::OK) + .content_type("text/html; charset=utf-8") + .body("

hello!

Are you looking for an API? Join our Discord!

Maybe you want to work with us? We can pay! Get in touch!

") +} diff --git a/app/storyteller_web/src/main.rs b/app/storyteller_web/src/main.rs index 23ede7aabf..d6ee668191 100644 --- a/app/storyteller_web/src/main.rs +++ b/app/storyteller_web/src/main.rs @@ -103,8 +103,6 @@ use crate::util::encrypted_sort_id::SortKeyCrypto; use futures::Future; use futures::executor::ThreadPool; //use http_server_common::cors::build_common_cors_config; -use http_server_common::endpoints::default_route_404::default_route_404; -use http_server_common::endpoints::root_index::get_root_index; use limitation::Limiter; use log::{info}; use r2d2_redis::RedisConnectionManager; @@ -114,6 +112,8 @@ use sqlx::MySqlPool; use sqlx::mysql::MySqlPoolOptions; use std::sync::Arc; use std::time::Duration; +use crate::http_server::endpoints::misc::root_index::get_root_index; +use crate::http_server::endpoints::misc::default_route_404::default_route_404; // TODO TODO TODO TODO // TODO TODO TODO TODO @@ -624,10 +624,13 @@ pub async fn serve(server_state: ServerState) -> AnyhowResult<()> .route(web::get().to(leaderboard_handler)) .route(web::head().to(|| HttpResponse::Ok())) ) - //.service(get_root_index) + .service(web::resource("/") + .route(web::get().to(get_root_index)) + .route(web::head().to(|| HttpResponse::Ok())) + ) .service(enable_alpha_handler) .service(enable_alpha_easy_handler) - //.default_service( web::route().to(default_route_404)) + .default_service( web::route().to(default_route_404)) }) .bind(bind_address)? .workers(num_workers)