async fn handle(req: Request<Body>, ctx: Arc<Context>) -> Response {
    trace!(
        "Incoming HTTP {:?} request to '{}{}'",
        req.method(),
        req.uri().path(),
        req.uri().query().map(|q| format!("?{}", q)).unwrap_or_default(),
    );

    let method = req.method().clone();
    let path = req.uri().path();

    const ASSET_PREFIX: &str = "/~assets/";

    match path {
        // The GraphQL endpoint. This is the only path for which POST is
        // allowed.
        "/graphql" if method == Method::POST => {
            juniper_hyper::graphql(ctx.api_root.clone(), ctx.api_context.clone(), req).await
        }

        // From this point on, we only support GET and HEAD requests. All others
        // will result in 404.
        _ if method != Method::GET && method != Method::HEAD => {
            Response::builder()
                .status(StatusCode::METHOD_NOT_ALLOWED)
                .header("Content-Type", "text/plain; charset=UTF-8")
                .body(Body::from("405 Method not allowed"))
                .unwrap()
        }

        // Assets (JS files, fonts, ...)
        path if path.starts_with(ASSET_PREFIX) => {
            let asset_path = &path[ASSET_PREFIX.len()..];
            match ctx.assets.serve(asset_path).await {
                Some(r) => r,
                None => reply_404(&ctx.assets, &method, path).await,
            }
        }


        // ----- Special, internal routes, starting with `/~` ----------------------------------
        "/~tobira" => ctx.assets.serve_index().await,

        // The interactive GraphQL API explorer/IDE. We actually keep this in
        // production as it does not hurt and in particular: does not expose any
        // information that isn't already exposed by the API itself.
        "/~graphiql" => juniper_hyper::graphiql("/graphql", None).await,

        path if path.starts_with("/~") => reply_404(&ctx.assets, &method, path).await,


        // Currently we just reply with our `index.html` to everything else.
        // That's of course not optimal because for many paths, our frontend
        // will show 404. It would be nice to reply 404 from the server
        // instead. But in order to do that, we would have to duplicate some
        // logic here. And since then we need to do a database lookup anyway,
        // we should probably already use that data and include it in the
        // `index.html`.
        //
        // I think doing all that is a good idea as soon as our routing logic is
        // fixed and doesn't change anymore. But for now, we avoid the
        // duplicate logic. So yeah:
        //
        // TODO: fix that at some point ^
        _ => ctx.assets.serve_index().await,
    }
}
/// This is the main entry point, called for each incoming request.
This is the main entry point, called for each incoming request.
This is the main entry point called for each incoming request .
async fn handle(req: Request<Body>, ctx: Arc<Context>) -> Response {
    trace!(
        "Incoming HTTP {:?} request to '{}{}'",
        req.method(),
        req.uri().path(),
        req.uri().query().map(|q| format!("?{}", q)).unwrap_or_default(),
    );
    let method = req.method().clone();
    let path = req.uri().path();
    const ASSET_PREFIX: &str = "/~assets/";
    match path {
        // The GraphQL endpoint. This is the only path for which POST is
        // allowed.
        "/graphql" if method == Method::POST => {
            juniper_hyper::graphql(ctx.api_root.clone(), ctx.api_context.clone(), req).await
        }
        // From this point on, we only support GET and HEAD requests. All others
        // will result in 404.
        _ if method != Method::GET && method != Method::HEAD => {
            Response::builder()
                .status(StatusCode::METHOD_NOT_ALLOWED)
                .header("Content-Type", "text/plain; charset=UTF-8")
                .body(Body::from("405 Method not allowed"))
                .unwrap()
        }
        // Assets (JS files, fonts, ...)
        path if path.starts_with(ASSET_PREFIX) => {
            let asset_path = &path[ASSET_PREFIX.len()..];
            match ctx.assets.serve(asset_path).await {
                Some(r) => r,
                None => reply_404(&ctx.assets, &method, path).await,
            }
        }
        // ----- Special, internal routes, starting with `/~` ----------------------------------
        "/~tobira" => ctx.assets.serve_index().await,
        // The interactive GraphQL API explorer/IDE. We actually keep this in
        // production as it does not hurt and in particular: does not expose any
        // information that isn't already exposed by the API itself.
        "/~graphiql" => juniper_hyper::graphiql("/graphql", None).await,
        path if path.starts_with("/~") => reply_404(&ctx.assets, &method, path).await,
        // Currently we just reply with our `index.html` to everything else.
        // That's of course not optimal because for many paths, our frontend
        // will show 404. It would be nice to reply 404 from the server
        // instead. But in order to do that, we would have to duplicate some
        // logic here. And since then we need to do a database lookup anyway,
        // we should probably already use that data and include it in the
        // `index.html`.
        //
        // I think doing all that is a good idea as soon as our routing logic is
        // fixed and doesn't change anymore. But for now, we avoid the
        // duplicate logic. So yeah:
        //
        // TODO: fix that at some point ^
        _ => ctx.assets.serve_index().await,
    }
}
async fn handle ( req : Request < Body > , ctx : Arc < Context > ) -> Response { trace ! ( " " req method ( ) req uri ( ) path ( ) req uri ( ) query ( ) map ( q format ( " " q ) ) unwrap_or_default ( ) ) ; let method = req . method ( ) . clone ( ) ; let path = req . uri ( ) . path ( ) ; const ASSET_PREFIX : & str = " " ; match path { // The GraphQL endpoint. This is the only path for which POST is // allowed. " " if method == Method :: POST => { juniper_hyper :: graphql ( ctx . api_root . clone ( ) , ctx . api_context . clone ( ) , req ) . await } // From this point on, we only support GET and HEAD requests. All others // will result in 404. _ if method != Method :: GET && method != Method :: HEAD => { Response :: builder ( ) . status ( StatusCode :: METHOD_NOT_ALLOWED ) . header ( " " , " " ) . body ( Body :: from ( " " ) ) . unwrap ( ) } // Assets (JS files, fonts, ...) path if path . starts_with ( ASSET_PREFIX ) => { let asset_path = & path [ ASSET_PREFIX . len ( ) .. ] ; match ctx . assets . serve ( asset_path ) . await { Some ( r ) => r , None => reply_404 ( & ctx . assets , & method , path ) . await , } } // ----- Special, internal routes, starting with `/~` ---------------------------------- " " => ctx . assets . serve_index ( ) . await , // The interactive GraphQL API explorer/IDE. We actually keep this in // production as it does not hurt and in particular: does not expose any // information that isn't already exposed by the API itself. " " => juniper_hyper :: graphiql ( " " , None ) . await , path if path . starts_with ( " " ) => reply_404 ( & ctx . assets , & method , path ) . await , // Currently we just reply with our `index.html` to everything else. // That's of course not optimal because for many paths, our frontend // will show 404. It would be nice to reply 404 from the server // instead. But in order to do that, we would have to duplicate some // logic here. And since then we need to do a database lookup anyway, // we should probably already use that data and include it in the // `index.html`. // // I think doing all that is a good idea as soon as our routing logic is // fixed and doesn't change anymore. But for now, we avoid the // duplicate logic. So yeah: // // TODO: fix that at some point ^ _ => ctx . assets . serve_index ( ) . await , } }
This is the main entry point, called for each incoming request.
This is the main entry point called for each incoming request .
req
Request<Body>
ctx
Arc<Context>