mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-05 01:38:44 +00:00
wip using common HTTP utils
This commit is contained in:
1 parent
7256630d87
commit
8a00f37e9e
4 files changed
+36
-43
No files matched your search
@@ -69,25 +69,12 @@ subprocess = "0.2.6"
|
||||
tempdir = "0.3.7"
|
||||
|
||||
# Web
|
||||
#actix = "0.12.0"
|
||||
actix-cors = "0.5.4"
|
||||
#actix-files= "0.5"
|
||||
|
||||
# NB: Versions aren't pinned since some apps use ver 3 vs ver 4.
|
||||
# This is because of the Tokio runtime requirements.
|
||||
actix-http = "*"
|
||||
#actix-multipart = "0.3.0" # TODO: Ready for 0.4 upgrade
|
||||
#actix-rt = "2.2.0"
|
||||
#actix-service = "1.0.6"
|
||||
#actix-utils = "3.0.0"
|
||||
actix-web = "*"
|
||||
#actix-web-actors = "3"
|
||||
#jwt = "0.13.0"
|
||||
|
||||
|
||||
#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-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 }
|
||||
|
||||
|
||||
|
||||
# NB: Hyper is just for HTTP client use in jobs. I'd use Actix client, but I need tokio runtime
|
||||
# NB: Furthermore, the Tokio runtime is old, so I have to use an older Hyper.
|
||||
@@ -112,7 +99,3 @@ pulldown-cmark = "0.8.0"
|
||||
[build-dependencies]
|
||||
# NB: Only using diesel for migrations support
|
||||
diesel = { version = "1.4.6", features = ["mysql"] }
|
||||
|
||||
#[features]
|
||||
#actix-old = ["actix-http-old", "actix-web-old"]
|
||||
#actix-new = ["actix-http-new", "actix-web-new"]
|
||||
@@ -6,4 +6,4 @@
|
||||
|
||||
pub mod cors;
|
||||
pub mod endpoints;
|
||||
pub mod response;
|
||||
pub mod response;
|
||||
@@ -1,16 +1,18 @@
|
||||
use actix_http::StatusCode;
|
||||
use actix_web::{HttpRequest, web, HttpResponse, ResponseError};
|
||||
use actix_http::{StatusCode, header};
|
||||
use actix_web::{HttpRequest, web, HttpResponse, ResponseError, HttpResponseBuilder};
|
||||
use crate::ObsGatewayServerState;
|
||||
use http_server_common::response::response_error_helpers::to_simple_json_error;
|
||||
use log::info;
|
||||
use std::fmt;
|
||||
use std::sync::Arc;
|
||||
use http_server_common::response::response_success_helpers::simple_json_success;
|
||||
|
||||
#[derive(Debug, Display)]
|
||||
#[derive(Debug)]
|
||||
pub enum OauthBeginEnrollError {
|
||||
ServerError,
|
||||
}
|
||||
|
||||
impl ResponseError for OauthBeginEnrollError{
|
||||
impl ResponseError for OauthBeginEnrollError {
|
||||
fn status_code(&self) -> StatusCode {
|
||||
match *self {
|
||||
Self::ServerError => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
@@ -22,14 +24,18 @@ impl ResponseError for OauthBeginEnrollError{
|
||||
Self::ServerError => "server error".to_string(),
|
||||
};
|
||||
|
||||
to_simple_json_error(&error_reason, self.status_code())
|
||||
//to_simple_json_error(&error_reason, self.status_code())
|
||||
|
||||
HttpResponseBuilder::new(self.status_code())
|
||||
.set_header(header::CONTENT_TYPE, "application/json")
|
||||
.body("TODO")
|
||||
}
|
||||
}
|
||||
|
||||
// NB: Not using DeriveMore since Clion doesn't understand it.
|
||||
impl fmt::Display for OauthBeginEnrollError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{:?}", self.error_type)
|
||||
write!(f, "{:?}", self)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,5 +46,9 @@ pub async fn oauth_begin_enroll(
|
||||
|
||||
|
||||
info!("oauth enrollment begin");
|
||||
Ok(())
|
||||
//Ok(simple_json_success())
|
||||
|
||||
Ok(HttpResponse::Ok()
|
||||
.content_type("application/json")
|
||||
.body(""))
|
||||
}
|
||||
+15
-15
@@ -12,14 +12,11 @@
|
||||
#[macro_use] extern crate magic_crypt;
|
||||
#[macro_use] extern crate serde_derive;
|
||||
|
||||
//pub mod endpoints;
|
||||
pub mod endpoints;
|
||||
pub mod pubsub_gateway;
|
||||
pub mod twitch;
|
||||
pub mod util;
|
||||
|
||||
//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 actix_cors::Cors;
|
||||
use actix_http::http;
|
||||
use actix_web::middleware::{Logger, DefaultHeaders};
|
||||
@@ -27,12 +24,16 @@ use actix_web::{HttpServer, web, HttpResponse, App};
|
||||
use config::shared_constants::DEFAULT_MYSQL_CONNECTION_STRING;
|
||||
use config::shared_constants::DEFAULT_REDIS_CONNECTION_STRING;
|
||||
use config::shared_constants::DEFAULT_RUST_LOG;
|
||||
use crate::endpoints::oauth_begin::oauth_begin_enroll;
|
||||
use crate::pubsub_gateway::ws_index;
|
||||
use crate::twitch::twitch_client_wrapper::TwitchClientWrapper;
|
||||
use crate::twitch::twitch_secrets::TwitchSecrets;
|
||||
use crate::twitch::websocket_client::PollingTwitchWebsocketClient;
|
||||
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;
|
||||
@@ -46,7 +47,6 @@ use twitch_api2::pubsub::Topic;
|
||||
use twitch_api2::pubsub;
|
||||
use twitch_oauth2::tokens::UserTokenBuilder;
|
||||
use twitch_oauth2::{AppAccessToken, Scope, TwitchToken, tokens::errors::AppAccessTokenError, ClientId, ClientSecret};
|
||||
//use crate::endpoints::oauth_begin::oauth_begin_enroll;
|
||||
|
||||
const DEFAULT_BIND_ADDRESS : &'static str = "0.0.0.0:12345";
|
||||
|
||||
@@ -323,16 +323,16 @@ pub async fn serve(server_state: ObsGatewayServerState) -> AnyhowResult<()>
|
||||
)
|
||||
// /twitch_oauth_enroll
|
||||
// /twitch_oauth_redirect
|
||||
// .service(
|
||||
// web::resource("/twitch_oauth_enroll")
|
||||
// .route(web::get().to(oauth_begin_enroll))
|
||||
// .route(web::head().to(|| HttpResponse::Ok()))
|
||||
// )
|
||||
// .service(
|
||||
// web::resource("/twitch_oauth_redirect")
|
||||
// .route(web::get().to(oauth_begin_enroll))
|
||||
// .route(web::head().to(|| HttpResponse::Ok()))
|
||||
// )
|
||||
.service(
|
||||
web::resource("/twitch_oauth_enroll")
|
||||
.route(web::get().to(oauth_begin_enroll))
|
||||
.route(web::head().to(|| HttpResponse::Ok()))
|
||||
)
|
||||
.service(
|
||||
web::resource("/twitch_oauth_redirect")
|
||||
.route(web::get().to(oauth_begin_enroll))
|
||||
.route(web::head().to(|| HttpResponse::Ok()))
|
||||
)
|
||||
//.default_service( web::route().to(default_route_404))
|
||||
})
|
||||
.bind(bind_address)?
|
||||
|
||||
Reference in new issue
Block a user