Add starter code for warp
This commit is contained in:
parent
0c868538b8
commit
f01b0181db
3 changed files with 1130 additions and 2 deletions
1107
Cargo.lock
generated
1107
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -7,3 +7,7 @@ edition = "2018"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
operational-transform = "0.6.0"
|
||||||
|
warp = "0.3.1"
|
||||||
|
tokio = { version = "1.6.1", features = ["full"] }
|
||||||
|
dotenv = "0.15.0"
|
||||||
|
|
21
src/main.rs
21
src/main.rs
|
@ -1,3 +1,20 @@
|
||||||
fn main() {
|
use warp::{filters::BoxedFilter, Filter, Reply};
|
||||||
println!("Hello, world!");
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue