child calls from main_responder (see route_dipatcher + route handlers) now borrow a connection for the sql db
This commit is contained in:
parent
19ad0eee9f
commit
d1cfc4284c
@ -23,6 +23,7 @@ mod auth;
|
|||||||
use auth::AuthReason;
|
use auth::AuthReason;
|
||||||
|
|
||||||
mod routes;
|
mod routes;
|
||||||
|
mod invites;
|
||||||
|
|
||||||
fn map_qs(query_string_raw: Option<&str>) -> HashMap<&str, &str> {
|
fn map_qs(query_string_raw: Option<&str>) -> HashMap<&str, &str> {
|
||||||
/*
|
/*
|
||||||
@ -42,9 +43,9 @@ fn map_qs(query_string_raw: Option<&str>) -> HashMap<&str, &str> {
|
|||||||
map
|
map
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn route_dispatcher(resp: &mut Response<Body>, meth: &Method, path: &str, params: &HashMap<&str, &str>) {
|
async fn route_dispatcher(conn: &Conn, resp: &mut Response<Body>, meth: &Method, path: &str, params: &HashMap<&str, &str>) {
|
||||||
match (meth, path) {
|
match (meth, path) {
|
||||||
(&Method::GET, routes::INVITE_JOIN) => invites::join_invite_code(&mut resp, meth, path, params),
|
(&Method::GET, routes::INVITE_JOIN) => invites::join_invite_code(conn, &mut resp, params).await,
|
||||||
_ => {
|
_ => {
|
||||||
*resp.status_mut() = StatusCode::NOT_FOUND;
|
*resp.status_mut() = StatusCode::NOT_FOUND;
|
||||||
}
|
}
|
||||||
@ -61,7 +62,7 @@ async fn main_responder(request: Request<Body>) -> Result<Response<Body>, hyper:
|
|||||||
if let Ok(conn) = Conn::from_url(env::var("DATABASE_URL").unwrap()).await {
|
if let Ok(conn) = Conn::from_url(env::var("DATABASE_URL").unwrap()).await {
|
||||||
// some more information in the response would be great right about here
|
// some more information in the response would be great right about here
|
||||||
match auth::wall_entry(path, conn, ¶ms).await {
|
match auth::wall_entry(path, conn, ¶ms).await {
|
||||||
OpenAuth | Good => route_dispatcher(&mut response, &method, path, ¶ms).await,
|
OpenAuth | Good => route_dispatcher(&conn, &mut response, &method, path, ¶ms).await,
|
||||||
LimitPassed => *response.status_mut() = StatusCode::UNAUTHORIZED,
|
LimitPassed => *response.status_mut() = StatusCode::UNAUTHORIZED,
|
||||||
NoKey => *response.status_mut() = StatusCode::UNAUTHORIZED,
|
NoKey => *response.status_mut() = StatusCode::UNAUTHORIZED,
|
||||||
InternalFailure => *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR
|
InternalFailure => *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR
|
||||||
|
Loading…
Reference in New Issue
Block a user