diff --git a/Cargo.toml b/Cargo.toml index f1e81c0..f88ef93 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,4 +3,5 @@ members = [ "itconfig", "itconfig_tests", "examples/diesel", + "examples/rocket", ] diff --git a/examples/rocket/Cargo.toml b/examples/rocket/Cargo.toml new file mode 100644 index 0000000..4b9f0cc --- /dev/null +++ b/examples/rocket/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "rocket" +version = "0.1.0" +authors = ["Dmitriy Pleshevskiy "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +rocket = "0.4.2" +itconfig = { path = '../../itconfig' } diff --git a/examples/rocket/src/main.rs b/examples/rocket/src/main.rs new file mode 100644 index 0000000..684d5cb --- /dev/null +++ b/examples/rocket/src/main.rs @@ -0,0 +1,36 @@ +#![feature(proc_macro_hygiene, decl_macro)] + +#[macro_use] +extern crate rocket; +#[macro_use] +extern crate itconfig; + +use rocket::config::{Config, Environment}; + +config! { + ROCKET { + HOST: String => "localhost".to_string(), + PORT: u16 => 8000, + BASE_URL: String => "/".to_string(), + } +} + + +#[get("/")] +fn index() -> &'static str { + "Hello, world!" +} + +fn main() { + cfg::init(); + + let config = Config::build(Environment::Staging) + .address(cfg::ROCKET::HOST()) + .port(cfg::ROCKET::PORT()) + .finalize() + .unwrap(); + + rocket::custom(config) + .mount(&cfg::ROCKET::BASE_URL(), routes![index]) + .launch(); +} \ No newline at end of file