mirror of
https://github.com/actix/examples
synced 2025-06-26 17:17:42 +02:00
standardize examples
This commit is contained in:
@ -5,6 +5,7 @@ edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
actix-web.workspace = true
|
||||
|
||||
casbin = "2"
|
||||
loge = { version = "0.4", default-features = false, features = ["colored", "chrono"] }
|
||||
tokio = { workspace = true, features = ["sync"] }
|
||||
env_logger.workspace = true
|
||||
tokio.workspace = true
|
||||
|
@ -23,10 +23,7 @@ async fn fail(enforcer: web::Data<RwLock<Enforcer>>, req: HttpRequest) -> HttpRe
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> io::Result<()> {
|
||||
std::env::set_var("RUST_LOG", "info");
|
||||
std::env::set_var("LOGE_FORMAT", "target");
|
||||
|
||||
loge::init();
|
||||
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
||||
|
||||
let model = DefaultModel::from_file("rbac/rbac_model.conf")
|
||||
.await
|
||||
|
@ -33,9 +33,9 @@ async fn index(session: Session, req: HttpRequest) -> Result<&'static str> {
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
std::env::set_var("RUST_LOG", "info");
|
||||
env_logger::init();
|
||||
log::info!("Starting http server: 127.0.0.1:8080");
|
||||
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
||||
|
||||
log::info!("starting HTTP server at http://localhost:8080");
|
||||
|
||||
HttpServer::new(|| {
|
||||
App::new()
|
||||
|
@ -4,20 +4,21 @@ version = "1.0.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
actix-web.workspace = true
|
||||
actix-identity.workspace = true
|
||||
actix-session = { workspace = true, features = ["cookie-session"] }
|
||||
actix-web.workspace = true
|
||||
|
||||
chrono = { version = "0.4.20", features = ["serde"] }
|
||||
derive_more.workspace = true
|
||||
diesel = { version = "2", features = ["postgres", "r2d2", "uuid", "chrono"] }
|
||||
dotenv = "0.15"
|
||||
env_logger.workspace = true
|
||||
log = "0.4"
|
||||
once_cell = "1"
|
||||
r2d2 = "0.8"
|
||||
rust-argon2 = "1"
|
||||
serde.workspace = true
|
||||
serde_json.workspace = true
|
||||
serde.workspace = true
|
||||
sparkpost = "0.5"
|
||||
uuid = { version = "1", features = ["v4", "serde"] }
|
||||
time = "0.3"
|
||||
uuid = { version = "1", features = ["v4", "serde"] }
|
||||
|
@ -4,10 +4,7 @@ extern crate diesel;
|
||||
use actix_identity::IdentityMiddleware;
|
||||
use actix_session::{config::PersistentSession, storage::CookieSessionStore, SessionMiddleware};
|
||||
use actix_web::{cookie::Key, middleware, web, App, HttpServer};
|
||||
use diesel::{
|
||||
prelude::*,
|
||||
r2d2::{self, ConnectionManager},
|
||||
};
|
||||
use diesel::{prelude::*, r2d2};
|
||||
use time::Duration;
|
||||
|
||||
mod auth_handler;
|
||||
@ -22,21 +19,19 @@ mod utils;
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
dotenv::dotenv().ok();
|
||||
std::env::set_var(
|
||||
"RUST_LOG",
|
||||
"simple-auth-server=debug,actix_web=info,actix_server=info",
|
||||
);
|
||||
env_logger::init();
|
||||
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
||||
|
||||
let database_url = std::env::var("DATABASE_URL").expect("DATABASE_URL must be set");
|
||||
|
||||
// create db connection pool
|
||||
let manager = ConnectionManager::<PgConnection>::new(database_url);
|
||||
let manager = r2d2::ConnectionManager::<PgConnection>::new(database_url);
|
||||
let pool: models::Pool = r2d2::Pool::builder()
|
||||
.build(manager)
|
||||
.expect("Failed to create pool.");
|
||||
let domain: String = std::env::var("DOMAIN").unwrap_or_else(|_| "localhost".to_string());
|
||||
|
||||
// Start http server
|
||||
log::info!("starting HTTP server at http://localhost:8080");
|
||||
|
||||
HttpServer::new(move || {
|
||||
App::new()
|
||||
.app_data(web::Data::new(pool.clone()))
|
||||
|
Reference in New Issue
Block a user