test routing

new-idea
Avril 4 years ago
parent c51f87e8cb
commit eeea6a13b1
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -56,3 +56,6 @@ static_assert!(STATE_STREAM_BUFFER_SIZE > 0);
///
/// TODO: Create `Version` type that takes from `env!(version)` at compile time.
pub const VERSION: u32 = 0;
/// Max size of a HTTP request body to process.
pub const MAX_CONTENT_LENGTH: u64 = (1024 * 1024) * 15; //15MB

@ -12,6 +12,8 @@ use tokio::{
mod command;
pub use command::*;
mod route;
/// Serve this state with this interrupt signal
pub fn serve(state: State) -> (InterruptChannel, impl Future<Output = eyre::Result<()>> + 'static)
{
@ -58,15 +60,16 @@ pub fn serve(state: State) -> (InterruptChannel, impl Future<Output = eyre::Resu
// setup server
let server = {
// TODO: warp routing paths
let routes = route::setup(state.clone());
clone!(command_channel);
async move {
mv![command_channel, // If we need to send commands to our own stream
state, // The program state
graceful_shutdown, // The graceful shutdown Future for warp.
//TODO: routing paths
routes,
];
// TODO: warp::try_serve...
// TODO: warp::try_serve... `routes`.
}
};
(command_channel,

@ -0,0 +1,55 @@
use super::*;
use warp::Filter;
use std::convert::Infallible;
use hard_format::{
FormattedString,
formats,
};
pub fn setup(state: State) -> impl warp::Filter //TODO: What output should this have?
{
let root = warp::path("yuurei"); //TODO: configurable
let state = warp::any().map(move || state.clone());
let post_api = warp::post()
.and(warp::path("create"))
.and(state.clone())
//TODO: Filter to extract `User`. How? Dunno. Maybe cookies + IP or in the body itself.
.and(warp::body::content_length_limit(defaults::MAX_CONTENT_LENGTH)) //TODO: configurable
.and(warp::body::json())
.and_then(|state: State, body: post::Post| { //TODO: post read is not this type, but another more restricted one
async move {
Ok::<_, Infallible>("test")
}
});
let get_api = warp::get()
.and(warp::path("get"))
.and({
let get_post_by_id = warp::any()
.and(warp::path("post"))
.and(state.clone())
.and(warp::path::param().map(|opt: formats::HexFormattedString| opt)) //TODO: Convert to `PostID`.
.and_then(|state: State, id: formats::HexFormattedString| {
async move {
Ok::<_, Infallible>("test")
}
});
let get_posts_by_user_id = warp::any()
.and(warp::path("user"))
.and(state.clone())
.and(warp::path::param().map(|opt: formats::HexFormattedString| opt)) //TODO: Convert to `UserID`.
.and_then(|state: State, id: formats::HexFormattedString| {
async move {
Ok::<_, Infallible>("test")
}
});
get_post_by_id
.or(get_posts_by_user_id)
});
root.and(post_api.
or(get_api))
}
Loading…
Cancel
Save