Testing
Because if I have to write one more curl statement, I'm going to lose it.
use sqlx::{Pool, Postgres};
use thruster::{
context::typed_hyper_context::TypedHyperContext, m, middleware_fn, App, HyperRequest,
MiddlewareNext, MiddlewareResult,
};
pub type Ctx = TypedHyperContext<RequestConfig>;
#[derive(Default)]
pub struct ServerConfig {}
#[derive(Default)]
pub struct RequestConfig {}
fn generate_context(request: HyperRequest, _state: &ServerConfig, _path: &str) -> Ctx {
Ctx::new(request, RequestConfig {})
}
#[middleware_fn]
async fn hello(mut context: Ctx, _next: MiddlewareNext<Ctx>) -> MiddlewareResult<Ctx> {
context.body("Hello, world!");
Ok(context)
}
pub async fn app(
_pool: Pool<Postgres>,
) -> Result<App<HyperRequest, Ctx, ServerConfig>, Box<dyn std::error::Error>> {
Ok(
App::<HyperRequest, Ctx, ServerConfig>::create(generate_context, ServerConfig {})
.get("/hello", m![hello]),
)
}
Last updated