Add the --bind option for listening on interfaces other than lo0

This commit is contained in:
R Tyler Croy 2019-12-02 07:12:13 -08:00
parent 4b802ad463
commit cef9a2f641
No known key found for this signature in database
GPG Key ID: E5C92681BEF6CEA2
3 changed files with 26 additions and 7 deletions

2
Cargo.lock generated
View File

@ -508,7 +508,7 @@ checksum = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f"
[[package]]
name = "kafkakitty"
version = "0.2.0"
version = "0.3.0"
dependencies = [
"clap",
"crossbeam",

View File

@ -1,6 +1,6 @@
[package]
name = "kafkakitty"
version = "0.2.0"
version = "0.3.0"
authors = ["R. Tyler Croy <rtyler@brokenco.de>"]
edition = "2018"

View File

@ -20,6 +20,8 @@ use log::warn;
use std::thread;
use std::time::Duration;
use rocket::config::{Config, Environment};
fn main() {
let matches = App::new("Kafkakitty 😿")
.version(option_env!("CARGO_PKG_VERSION").unwrap_or(""))
@ -63,11 +65,19 @@ fn main() {
.takes_value(true)
.multiple(true),
)
.arg(
Arg::with_name("bindhost")
.long("bind")
.help("Bind to an address other than localhost")
.takes_value(true)
.required(false)
.default_value("localhost")
)
.get_matches();
let should_open = !matches.is_present("no-open");
let mut settings: Vec<(String, String)> = vec![(String::from("group.id"), String::from("fo"))];
let bindhost = String::from(matches.value_of("bindhost").unwrap());
let mut settings: Vec<(String, String)> = vec![];
// Default settings for librdkafka
for (key, value) in [
@ -128,8 +138,12 @@ fn main() {
});
thread::spawn(move || {
let topics = matches.values_of("topics").unwrap().collect::<Vec<&str>>();
/*
* Processing matches in this closure in order to prefer moving the matches reference into
* this thread, rather than computing topics outside the thread and then trying to move
* those string reference inside the thread.
*/
let topics: Vec<&str> = matches.values_of("topics").unwrap().collect();
kafka::consume(sender, settings, &topics);
});
@ -142,8 +156,13 @@ fn main() {
});
}
let web_config = Config::build(Environment::Development)
.address(bindhost)
.port(8000)
.finalize().unwrap();
// Launch the web app
rocket::ignite()
rocket::custom(web_config)
.mount("/", routes![routes::index, routes::assets])
.launch();
}