Webapp boilerplate

This commit is contained in:
Félix Baylac Jacqué 2022-12-20 19:21:05 +01:00
parent 90267bd9a3
commit 1fdaa156db
6 changed files with 1256 additions and 3 deletions

1
.envrc Normal file
View File

@ -0,0 +1 @@
use nix

1227
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -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"

View File

@ -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=";
}

View File

@ -4,5 +4,6 @@ pkgs.mkShell {
nativeBuildInputs = [
pkgs.rustc
pkgs.cargo
pkgs.rust-analyzer
];
}

View File

@ -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");
}