refactor: migrate to axum 0.7

This commit is contained in:
Sandro Eiler 2023-12-15 23:13:00 +01:00
parent 57704def31
commit e1e544267d
5 changed files with 159 additions and 43 deletions

View file

@ -3,15 +3,13 @@ use axum::extract::{Path, Query};
use axum::http::{Method, Uri};
use axum::response::{Html, IntoResponse, Response};
use axum::routing::{get, get_service, post, IntoMakeService};
use axum::Server;
use axum::serve::Serve;
use axum::{middleware, Json, Router};
use hyper::server::conn::AddrIncoming;
use serde::Deserialize;
use serde_json::{json, Value};
use std::net::SocketAddr;
use std::net::TcpListener;
pub type App = Server<AddrIncoming, IntoMakeService<Router>>;
use tokio::net::TcpListener;
#[derive(Deserialize)]
struct FormData {
@ -20,15 +18,13 @@ struct FormData {
}
/// API routing
fn app() -> Router {
pub fn app() -> Router {
Router::new()
.route("/health_check", get(|| async {}))
.route("/subscriptions", post(|| async {}))
}
/// Start the server
pub fn run(listener: TcpListener) -> hyper::Result<App> {
let app = app();
let server = Server::from_tcp(listener)?.serve(app.into_make_service());
Ok(server)
pub fn run(listener: TcpListener) -> Serve<IntoMakeService<Router>, Router> {
axum::serve(listener, app().into_make_service())
}