-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* adopt actix-settings crate * add licenses and readme addition * revamp readme * delete temp prettier file
- Loading branch information
Showing
14 changed files
with
1,604 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,5 @@ guide/build/ | |
*.sock | ||
*~ | ||
.DS_Store | ||
|
||
Server.toml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Changes | ||
|
||
## Unreleased - 2022-xx-xx | ||
- Update Actix Web dependencies to v4 ecosystem. | ||
- Rename `actix.ssl` settings object to `actix.tls`. | ||
- `NoSettings` is now marked `#[non_exhaustive]`. | ||
|
||
## 0.5.2 - 2022-07-31 | ||
- Adopted into @actix org from <https://github.com/jjpe/actix-settings>. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
[package] | ||
name = "actix-settings" | ||
version = "0.5.2" | ||
authors = [ | ||
"Joey Ezechiels <[email protected]>", | ||
"Rob Ede <[email protected]>", | ||
] | ||
edition = "2018" | ||
description = "Easily manage Actix Web's settings from a TOML file and environment variables" | ||
license = "MIT OR Apache-2.0" | ||
|
||
[dependencies] | ||
actix-http = "3" | ||
actix-service = "2" | ||
actix-web = "4" | ||
|
||
ioe = "0.5" | ||
once_cell = "1.13" | ||
regex = "1.5.5" | ||
serde = { version = "1", features = ["derive"] } | ||
toml = "0.5" | ||
|
||
[dev-dependencies] | ||
env_logger = "0.9" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../LICENSE-APACHE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../LICENSE-MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# actix-settings | ||
|
||
> Easily manage Actix Web's settings from a TOML file and environment variables. | ||
[](https://crates.io/crates/actix-settings) | ||
[](https://docs.rs/actix-settings/0.5.2) | ||
 | ||
[](https://deps.rs/crate/actix-settings/0.5.2) | ||
|
||
## Documentation & Resources | ||
|
||
- [API Documentation](https://docs.rs/actix-settings) | ||
- [Usage Example][usage] | ||
- Minimum Supported Rust Version (MSRV): 1.57 | ||
|
||
### Custom Settings | ||
|
||
There is a way to extend the available settings. This can be used to combine the settings provided by Actix Web and those provided by application server built using `actix`. | ||
|
||
Have a look at [the usage example][usage] to see how. | ||
|
||
## WIP | ||
|
||
Configuration options for TLS set up are not yet implemented. | ||
|
||
## Special Thanks | ||
|
||
This crate was made possible by support from Accept B.V and [@jjpe]. | ||
|
||
[usage]: https://github.com/actix/actix-extras/blob/master/actix-settings/examples/actix.rs | ||
[@jjpe]: https://github.com/jjpe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
use actix_settings::{ApplySettings as _, Mode, Settings}; | ||
use actix_web::{ | ||
get, | ||
middleware::{Compress, Condition, Logger}, | ||
web, App, HttpServer, Responder, | ||
}; | ||
|
||
#[get("/")] | ||
async fn index(settings: web::Data<Settings>) -> impl Responder { | ||
format!( | ||
r#"{{ | ||
"mode": "{}", | ||
"hosts": ["{}"] | ||
}}"#, | ||
match settings.actix.mode { | ||
Mode::Development => "development", | ||
Mode::Production => "production", | ||
}, | ||
settings | ||
.actix | ||
.hosts | ||
.iter() | ||
.map(|addr| { format!("{}:{}", addr.host, addr.port) }) | ||
.collect::<Vec<_>>() | ||
.join(", "), | ||
) | ||
.customize() | ||
.insert_header(("content-type", "application/json")) | ||
} | ||
|
||
#[actix_web::main] | ||
async fn main() -> std::io::Result<()> { | ||
let mut settings = Settings::parse_toml("./examples/Server.toml") | ||
.expect("Failed to parse `Settings` from Server.toml"); | ||
|
||
// If the environment variable `$APPLICATION__HOSTS` is set, | ||
// have its value override the `settings.actix.hosts` setting: | ||
Settings::override_field_with_env_var(&mut settings.actix.hosts, "APPLICATION__HOSTS")?; | ||
|
||
init_logger(&settings); | ||
|
||
HttpServer::new({ | ||
// clone settings into each worker thread | ||
let settings = settings.clone(); | ||
|
||
move || { | ||
App::new() | ||
// Include this `.wrap()` call for compression settings to take effect: | ||
.wrap(Condition::new( | ||
settings.actix.enable_compression, | ||
Compress::default(), | ||
)) | ||
.wrap(Logger::default()) | ||
// make `Settings` available to handlers | ||
.app_data(web::Data::new(settings.clone())) | ||
.service(index) | ||
} | ||
}) | ||
// apply the `Settings` to Actix Web's `HttpServer` | ||
.apply_settings(&settings) | ||
.run() | ||
.await | ||
} | ||
|
||
/// Initialize the logging infrastructure | ||
fn init_logger(settings: &Settings) { | ||
if !settings.actix.enable_log { | ||
return; | ||
} | ||
|
||
std::env::set_var( | ||
"RUST_LOG", | ||
match settings.actix.mode { | ||
Mode::Development => "actix_web=debug", | ||
Mode::Production => "actix_web=info", | ||
}, | ||
); | ||
|
||
std::env::set_var("RUST_BACKTRACE", "1"); | ||
|
||
env_logger::init(); | ||
} |
Oops, something went wrong.