mirror of
https://github.com/rjNemo/rust-web
synced 2026-06-06 02:46:41 +00:00
env variables
This commit is contained in:
parent
78e8ea4aa4
commit
5813dd6ad5
6 changed files with 19 additions and 4 deletions
1
.env
Normal file
1
.env
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
BASE_URL=127.0.0.1:8000
|
||||||
1
.env.example
Normal file
1
.env.example
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
BASE_URL=127.0.0.1:8000
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,2 +1,3 @@
|
||||||
/target
|
/target
|
||||||
/.idea
|
/.idea
|
||||||
|
.env
|
||||||
7
Cargo.lock
generated
7
Cargo.lock
generated
|
|
@ -507,6 +507,12 @@ version = "1.0.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0"
|
checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "dotenv"
|
||||||
|
version = "0.15.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "either"
|
name = "either"
|
||||||
version = "1.6.1"
|
version = "1.6.1"
|
||||||
|
|
@ -1757,6 +1763,7 @@ name = "web"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-web",
|
"actix-web",
|
||||||
|
"dotenv",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -8,5 +8,6 @@ edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-web = "3"
|
actix-web = "3"
|
||||||
serde = "1.0.118"
|
dotenv = "0.15.0"
|
||||||
env_logger = "0.8.2"
|
env_logger = "0.8.2"
|
||||||
|
serde = "1.0.118"
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
use std::env;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
|
|
||||||
use actix_web::{middleware, web, App, HttpServer};
|
use actix_web::{middleware, web, App, HttpServer};
|
||||||
|
|
@ -9,6 +10,9 @@ mod task;
|
||||||
#[actix_web::main]
|
#[actix_web::main]
|
||||||
async fn main() -> std::io::Result<()> {
|
async fn main() -> std::io::Result<()> {
|
||||||
env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();
|
env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();
|
||||||
|
dotenv::dotenv().ok();
|
||||||
|
|
||||||
|
let addr = env::var("BASE_URL").unwrap();
|
||||||
|
|
||||||
let tasks = web::Data::new(task::TaskList {
|
let tasks = web::Data::new(task::TaskList {
|
||||||
tasks: Mutex::new(vec![
|
tasks: Mutex::new(vec![
|
||||||
|
|
@ -31,7 +35,7 @@ async fn main() -> std::io::Result<()> {
|
||||||
.app_data(tasks.clone())
|
.app_data(tasks.clone())
|
||||||
.configure(task::init)
|
.configure(task::init)
|
||||||
})
|
})
|
||||||
.bind("127.0.0.1:8000")?
|
.bind(addr)?
|
||||||
.run()
|
.run()
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue