Add starter code for warp

This commit is contained in:
Eric Zhang 2021-05-31 12:09:30 -05:00
parent 0c868538b8
commit f01b0181db
3 changed files with 1130 additions and 2 deletions

1107
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -7,3 +7,7 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
operational-transform = "0.6.0"
warp = "0.3.1"
tokio = { version = "1.6.1", features = ["full"] }
dotenv = "0.15.0"

View file

@ -1,3 +1,20 @@
fn main() {
println!("Hello, world!");
use warp::{filters::BoxedFilter, Filter, Reply};
fn server() -> BoxedFilter<(impl Reply,)> {
(warp::path!("hello" / String).map(|name| format!("Hello, {}!", name)))
.or(warp::path::end().map(|| "Home page"))
.boxed()
}
#[tokio::main]
async fn main() {
dotenv::dotenv().ok();
let port = std::env::var("PORT")
.unwrap_or("3030".to_string())
.parse()
.expect("Unable to parse PORT");
println!("Server listening on http://localhost:{}", port);
warp::serve(server()).run(([0, 0, 0, 0], port)).await;
}