Browse Source

Initial actix-web demoing

master
Drew Short 6 years ago
commit
c1346e0720
  1. 2
      .gitignore
  2. 2013
      Cargo.lock
  3. 10
      Cargo.toml
  4. 44
      src/main.rs
  5. 7
      src/server.rs

2
.gitignore

@ -0,0 +1,2 @@
/target
**/*.rs.bk

2013
Cargo.lock
File diff suppressed because it is too large
View File

10
Cargo.toml

@ -0,0 +1,10 @@
[package]
name = "ddns"
version = "0.1.0"
authors = ["Drew Short <warrick@sothr.com>"]
[dependencies]
clap = "2.32.0"
yaml-rust = "0.4.0"
actix-web = "0.7.7"
cloudflare = { git = "https://github.com/nocduro/cloudflare-rs", branch = "master" }

44
src/main.rs

@ -0,0 +1,44 @@
extern crate actix_web;
extern crate clap;
use clap::{App, Arg};
mod server;
fn main() {
let args = App::new("Dynamic DNS Server")
.version("0.1")
.author("Drew Short <warrick@sothr.com>")
.about("Recieve DDNS requests and update cloudflare subdomains")
.arg(
Arg::with_name("config")
.short("c")
.long("config")
.value_name("PATH")
.help("Set a custom configuration file path. DEFAULT=/etc/rsddns/rsddns.yml.")
.takes_value(true),
)
.arg(
Arg::with_name("port")
.short("p")
.long("port")
.value_name("PORT")
.help("The port to run the server on.")
.takes_value(true),
)
.get_matches();
let config: &str = args.value_of("config").unwrap_or("/etc/rsddns/rsddns.yml");
let port: i32 = args
.value_of("port")
.unwrap_or("8080")
.parse::<i32>()
.unwrap_or(8080);
println!("Starting server on {} with config {}", port, config);
actix_web::server::new(|| actix_web::App::new().resource("/", |r| r.f(server::index)))
.bind(format!("localhost:{}", port))
.unwrap()
.run();
}

7
src/server.rs

@ -0,0 +1,7 @@
extern crate actix_web;
use actix_web::HttpRequest;
pub fn index(_req: &HttpRequest) -> &'static str {
"Hello, World!"
}
Loading…
Cancel
Save