Webapp boilerplate
This commit is contained in:
parent
90267bd9a3
commit
1fdaa156db
File diff suppressed because it is too large
Load Diff
|
@ -6,3 +6,6 @@ edition = "2021"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
clap = { version = "4.0.29", features = ["derive"] }
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
warp = "0.3"
|
||||
|
|
|
@ -4,5 +4,5 @@ pkgs.rustPlatform.buildRustPackage {
|
|||
pname = "nom-nom-nix-gc";
|
||||
version = "0.0";
|
||||
src = pkgs.lib.cleanSource ./.;
|
||||
cargoHash = "sha256-yTbzY1PGxwevQ07LRSqIj/yzukxFOI427Yc6eE0KZc8=";
|
||||
cargoHash = "sha256-3qIr0VcstuG/xzUTO5TAguJ9ZTmQsYMSw5VXyuY2HMc=";
|
||||
}
|
||||
|
|
|
@ -4,5 +4,6 @@ pkgs.mkShell {
|
|||
nativeBuildInputs = [
|
||||
pkgs.rustc
|
||||
pkgs.cargo
|
||||
pkgs.rust-analyzer
|
||||
];
|
||||
}
|
||||
|
|
25
src/main.rs
25
src/main.rs
|
@ -1,3 +1,24 @@
|
|||
fn main() {
|
||||
println!("Hello, world!");
|
||||
use std::net::SocketAddr;
|
||||
use clap::Parser;
|
||||
use warp::Filter;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(author, version, about, long_about = None)]
|
||||
struct CLIArgs {
|
||||
#[arg(short, long)]
|
||||
bind: String
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let args = CLIArgs::parse();
|
||||
let addr: SocketAddr = args.bind.parse().expect(&format!("Cannot bind to {}. Please provide a host and port like [::1]:8000", &args.bind));
|
||||
|
||||
println!("Server listening to {}", &args.bind);
|
||||
|
||||
let routes = warp::any().map(|| "Hello, World!");
|
||||
warp::serve(routes).run(addr).await;
|
||||
|
||||
println!("Turning out server");
|
||||
println!("Adieu");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue