Upgrade to Tokio 1.x, futures 0.3, Hyper 0.14, etc (#459)

* Upgrade dependencies, oneshot channel ref

* New service style?

* Fix warning

* A server is running again

* Working server with async blocks

* UI working again

* Finish upgrade

* Bump MSRV to 1.46.0 for if/match in const fn

* Update the README as part of this
This commit is contained in:
Lucien Greathouse
2021-07-28 12:29:46 -04:00
committed by GitHub
parent 4aa5814a0a
commit 5d62bf9b60
10 changed files with 422 additions and 285 deletions

View File

@@ -6,8 +6,7 @@
use std::{borrow::Cow, sync::Arc, time::Duration};
use futures::{future, Future};
use hyper::{header, service::Service, Body, Method, Request, Response, StatusCode};
use hyper::{header, Body, Method, Request, Response, StatusCode};
use maplit::hashmap;
use rbx_dom_weak::types::{Ref, Variant};
use ritz::{html, Fragment, HtmlContent, HtmlSelfClosingTag};
@@ -22,32 +21,23 @@ use crate::{
},
};
pub struct UiService {
serve_session: Arc<ServeSession>,
pub async fn call(serve_session: Arc<ServeSession>, request: Request<Body>) -> Response<Body> {
let service = UiService::new(serve_session);
match (request.method(), request.uri().path()) {
(&Method::GET, "/") => service.handle_home(),
(&Method::GET, "/logo.png") => service.handle_logo(),
(&Method::GET, "/icon.png") => service.handle_icon(),
(&Method::GET, "/show-instances") => service.handle_show_instances(),
(_method, path) => json(
ErrorResponse::not_found(format!("Route not found: {}", path)),
StatusCode::NOT_FOUND,
),
}
}
impl Service for UiService {
type ReqBody = Body;
type ResBody = Body;
type Error = hyper::Error;
type Future = Box<dyn Future<Item = Response<Self::ReqBody>, Error = Self::Error> + Send>;
fn call(&mut self, request: Request<Self::ReqBody>) -> Self::Future {
let response = match (request.method(), request.uri().path()) {
(&Method::GET, "/") => self.handle_home(),
(&Method::GET, "/logo.png") => self.handle_logo(),
(&Method::GET, "/icon.png") => self.handle_icon(),
(&Method::GET, "/show-instances") => self.handle_show_instances(),
(_method, path) => {
return json(
ErrorResponse::not_found(format!("Route not found: {}", path)),
StatusCode::NOT_FOUND,
)
}
};
Box::new(future::ok(response))
}
pub struct UiService {
serve_session: Arc<ServeSession>,
}
impl UiService {