Skip to content

Commit

Permalink
Add logging
Browse files Browse the repository at this point in the history
  • Loading branch information
belst committed Dec 19, 2021
1 parent d6d9172 commit 9d8a616
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
49 changes: 49 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ serde_json = "1.0.64"
dotenv = "0.15"
chrono = { version = "0.4.19", features = ["serde"] }
url = "2.2.2"
env_logger = "0.9.0"

[dependencies.sqlx]
version = "0.5.9"
Expand Down
11 changes: 8 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use actix_cors::Cors;
use actix_identity::{CookieIdentityPolicy, Identity, IdentityService};
use actix_web::{post, web, App, HttpResponse, HttpServer, Responder};
use actix_web::{post, web, App, HttpResponse, HttpServer, Responder, middleware::Logger};
use anyhow::bail;
use chrono::Utc;
use dotenv::dotenv;
use env_logger::Env;
use rand::Rng;
use serde::{Deserialize, Serialize};
use sqlx::{postgres::PgPoolOptions, FromRow, Pool, Postgres};
Expand Down Expand Up @@ -86,7 +87,7 @@ async fn webhook(body: web::Json<Config>, db: web::Data<PgPool>) -> impl Respond
Ok(url) => url,
Err(e) => {
println!("{}", e);
return HttpResponse::Unauthorized().json(Response::new(
return HttpResponse::Ok().json(Response::new(
false,
None,
None,
Expand All @@ -109,7 +110,7 @@ async fn webhook(body: web::Json<Config>, db: web::Data<PgPool>) -> impl Respond
return HttpResponse::Ok().json(Response::allowed());
}
}
HttpResponse::Unauthorized().json(Response::new(
HttpResponse::Ok().json(Response::new(
false,
None,
None,
Expand Down Expand Up @@ -241,13 +242,17 @@ async fn main() -> anyhow::Result<()> {
let db_url = env::var("DATABASE_URL").expect("DATABASE_URL is not set");
let host = env::var("HOST").expect("HOST is not set");
let port = env::var("PORT").expect("PORT is not set");

env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();

let db_pool: PgPool = PgPoolOptions::new().connect(&db_url).await?;

sqlx::migrate!("./migrations").run(&db_pool).await?;

let secret: [u8; 32] = rand::thread_rng().gen();
HttpServer::new(move || {
App::new()
.wrap(Logger::default())
.wrap(Cors::permissive())
.wrap(IdentityService::new(
CookieIdentityPolicy::new(&secret).name("auth").secure(true),
Expand Down

0 comments on commit 9d8a616

Please sign in to comment.