Browse Source

auth route

pull/25/head
Alexey Velikiy 3 years ago
parent
commit
a49016d798
  1. 25
      server/src/api.rs
  2. 17
      server/src/api/auth.rs

25
server/src/api.rs

@ -1,19 +1,14 @@
use warp::{Rejection, Reply, body};
use warp::{Filter, http::Response };
use warp::filters::method::post;
use crate::user_service;
pub struct API {
mod auth;
}
pub struct API {
fn json_body() -> impl Filter<Extract = (user_service::User,), Error = warp::Rejection> + Clone {
// When accepting a body, we want a JSON body
// (and to reject huge payloads)...
warp::body::content_length_limit(1024 * 16).and(warp::body::json())
}
impl API {
@ -27,21 +22,17 @@ impl API {
.header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE")
.header("Access-Control-Allow-Headers", "*")
.body(s.to_owned())
}
pub async fn serve() {
let lg = warp::any().map(move || API::builder("not found") );
let login = warp::any()
// path!("api" / "auth" / "signin")
.and(post())
.and(json_body())
.map(|user: user_service::User| {
let s = format!("Hello, {}!", &user.username);
API::builder(&s)
});
let login = auth::get_route();
println!("Start server on 8000 port");
warp::serve(login.or(lg))
warp::serve(login.
or(lg)
)
.run(([127, 0, 0, 1], 8000))
.await;
}

17
server/src/api/auth.rs

@ -0,0 +1,17 @@
use crate::api::API;
use crate::user_service;
use warp::{Rejection, Reply};
use warp::filters::method::post;
use warp::{Filter, http::Response };
pub fn get_route() -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
return warp::path!("api" / "auth" / "signin")
.and(post())
.and(warp::body::json())
.map(|user: user_service::User| {
let s = format!("Hello, {}!", &user.username);
API::builder(&s)
});
}
Loading…
Cancel
Save