add possibility to load env from .env file
This commit is contained in:
parent
186b456d2a
commit
f777646394
|
@ -467,6 +467,7 @@ name = "bot"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
|
"dotenvy",
|
||||||
"graphql_client",
|
"graphql_client",
|
||||||
"poise",
|
"poise",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
|
@ -732,6 +733,7 @@ dependencies = [
|
||||||
"actix-cors",
|
"actix-cors",
|
||||||
"actix-web",
|
"actix-web",
|
||||||
"chrono",
|
"chrono",
|
||||||
|
"dotenvy",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"juniper 0.16.0-dev",
|
"juniper 0.16.0-dev",
|
||||||
"juniper_actix",
|
"juniper_actix",
|
||||||
|
@ -786,6 +788,12 @@ dependencies = [
|
||||||
"crypto-common",
|
"crypto-common",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "dotenvy"
|
||||||
|
version = "0.15.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "either"
|
name = "either"
|
||||||
version = "1.9.0"
|
version = "1.9.0"
|
||||||
|
|
|
@ -7,6 +7,7 @@ description = "Discord bot"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
chrono = { version = "0.4", features = ["serde"] }
|
chrono = { version = "0.4", features = ["serde"] }
|
||||||
|
dotenvy = "0.15"
|
||||||
graphql_client = { version = "0.13", features = ["reqwest"] }
|
graphql_client = { version = "0.13", features = ["reqwest"] }
|
||||||
poise = "0.5"
|
poise = "0.5"
|
||||||
reqwest = { version = "0.11", features = ["json"] }
|
reqwest = { version = "0.11", features = ["json"] }
|
||||||
|
|
|
@ -8,6 +8,13 @@ use reqwest::Client;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
|
match dotenvy::dotenv() {
|
||||||
|
Ok(_) => {}
|
||||||
|
Err(e) => {
|
||||||
|
println!("Failed to load .env file: {}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let framework = poise::Framework::builder()
|
let framework = poise::Framework::builder()
|
||||||
.options(poise::FrameworkOptions {
|
.options(poise::FrameworkOptions {
|
||||||
commands: vec![help(), add(), list(), search(), remove(), update()],
|
commands: vec![help(), add(), list(), search(), remove(), update()],
|
||||||
|
|
|
@ -9,6 +9,7 @@ description = "Database endpoint with GraphQL for tech-bot"
|
||||||
actix-cors = "0.6"
|
actix-cors = "0.6"
|
||||||
actix-web = "4.3"
|
actix-web = "4.3"
|
||||||
chrono = { version = "0.4", features = ["serde"] }
|
chrono = { version = "0.4", features = ["serde"] }
|
||||||
|
dotenvy = "0.15"
|
||||||
env_logger = "0.10"
|
env_logger = "0.10"
|
||||||
# until v0.16 is released, use master for uuid support
|
# until v0.16 is released, use master for uuid support
|
||||||
juniper = { git = "https://github.com/graphql-rust/juniper.git", features = [
|
juniper = { git = "https://github.com/graphql-rust/juniper.git", features = [
|
||||||
|
|
|
@ -40,6 +40,13 @@ static CONTEXT: OnceLock<DB> = OnceLock::new();
|
||||||
|
|
||||||
#[actix_web::main]
|
#[actix_web::main]
|
||||||
async fn main() -> io::Result<()> {
|
async fn main() -> io::Result<()> {
|
||||||
|
match dotenvy::dotenv() {
|
||||||
|
Ok(_) => {}
|
||||||
|
Err(e) => {
|
||||||
|
println!("Failed to load .env file: {}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
||||||
|
|
||||||
// Create Juniper schema
|
// Create Juniper schema
|
||||||
|
@ -59,7 +66,13 @@ async fn main() -> io::Result<()> {
|
||||||
.wrap(Cors::permissive())
|
.wrap(Cors::permissive())
|
||||||
.wrap(middleware::Logger::default())
|
.wrap(middleware::Logger::default())
|
||||||
})
|
})
|
||||||
.bind(("127.0.0.1", 8080))?
|
.bind((
|
||||||
|
std::env::var("HOST").unwrap_or(String::from("127.0.0.1")),
|
||||||
|
std::env::var("PORT")
|
||||||
|
.unwrap_or(String::from("8080"))
|
||||||
|
.parse::<u16>()
|
||||||
|
.expect("failed to convert port to u16"),
|
||||||
|
))?
|
||||||
.run()
|
.run()
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue