mirror of https://github.com/mastodon/flodgatt
Merge pull request #24 from tootsuite/hotfix
Hotfix for typo and logging
This commit is contained in:
commit
6953b325cf
11
src/.env
11
src/.env
|
@ -1,6 +1,11 @@
|
||||||
# Uncomment any of the variables below to customize your enviornment
|
# Uncomment any of the variables below to customize your enviornment
|
||||||
|
|
||||||
#SERVER_ADDR=
|
|
||||||
#REDIS_ADDR=
|
|
||||||
#POSTGRES_ADDR=
|
#POSTGRES_ADDR=
|
||||||
CORS_ALLOWED_METHODS="GET OPTIONS"
|
#REDIS_ADDR=
|
||||||
|
#SERVER_ADDR=
|
||||||
|
#SSE_UPDATE_INTERVAL=
|
||||||
|
#WS_UPDATE_INTERVAL=
|
||||||
|
#REDIS_POLL_INTERVAL=
|
||||||
|
|
||||||
|
#Possible values for the log level are eror, warn, info, debug, trace
|
||||||
|
RUST_LOG=warn
|
|
@ -18,15 +18,21 @@ const DEFAULT_WS_UPDATE_INTERVAL: u64 = 100;
|
||||||
const DEFAULT_REDIS_POLL_INTERVAL: u64 = 100;
|
const DEFAULT_REDIS_POLL_INTERVAL: u64 = 100;
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref POSTGRES_ADDR: String = env::var("POSTGRESS_ADDR").unwrap_or_else(|_| {
|
static ref POSTGRES_ADDR: String = env::var("POSTGRES_ADDR").unwrap_or_else(|_| {
|
||||||
let mut postgres_addr = DEFAULT_POSTGRES_ADDR.to_string();
|
warn!("No POSTGRES_ADDR env variable set; using default postgres address.");
|
||||||
postgres_addr.insert_str(11,
|
match &env::var("USER") {
|
||||||
&env::var("USER").unwrap_or_else(|_| {
|
Err(_) => {
|
||||||
warn!("No USER env variable set. Connecting to Postgress with default `postgres` user");
|
let addr = DEFAULT_POSTGRES_ADDR.replace("@", format!("{}@", "postgres").as_str());
|
||||||
"postgres".to_string()
|
warn!("No USER env variable set; using default `postgres` user.\n Using postgres address: {}\n", addr);
|
||||||
}).as_str()
|
addr
|
||||||
);
|
},
|
||||||
postgres_addr
|
Ok(user) => {
|
||||||
|
let addr = DEFAULT_POSTGRES_ADDR.replace("@", format!("{}@", user).as_str());
|
||||||
|
warn!("Connecting to postgres with current user.\n Using postgres address: {}\n", addr);
|
||||||
|
addr
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
static ref REDIS_ADDR: String = env::var("REDIS_ADDR").unwrap_or_else(|_| DEFAULT_REDIS_ADDR.to_owned());
|
static ref REDIS_ADDR: String = env::var("REDIS_ADDR").unwrap_or_else(|_| DEFAULT_REDIS_ADDR.to_owned());
|
||||||
|
@ -64,8 +70,9 @@ pub fn cross_origin_resource_sharing() -> warp::filters::cors::Cors {
|
||||||
|
|
||||||
/// Initialize logging and read values from `src/.env`
|
/// Initialize logging and read values from `src/.env`
|
||||||
pub fn logging_and_env() {
|
pub fn logging_and_env() {
|
||||||
pretty_env_logger::init();
|
|
||||||
dotenv().ok();
|
dotenv().ok();
|
||||||
|
pretty_env_logger::init();
|
||||||
|
POSTGRES_ADDR.to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Configure Postgres and return a connection
|
/// Configure Postgres and return a connection
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use log::{log_enabled, Level};
|
||||||
use ragequit::{
|
use ragequit::{
|
||||||
any_of, config,
|
any_of, config,
|
||||||
parse_client_request::{sse, user, ws},
|
parse_client_request::{sse, user, ws},
|
||||||
|
@ -12,6 +13,10 @@ fn main() {
|
||||||
let client_agent_sse = ClientAgent::blank();
|
let client_agent_sse = ClientAgent::blank();
|
||||||
let client_agent_ws = client_agent_sse.clone_with_shared_receiver();
|
let client_agent_ws = client_agent_sse.clone_with_shared_receiver();
|
||||||
|
|
||||||
|
if log_enabled!(Level::Warn) {
|
||||||
|
println!("Streaming server initialized and ready to accept connections");
|
||||||
|
};
|
||||||
|
|
||||||
// Server Sent Events
|
// Server Sent Events
|
||||||
//
|
//
|
||||||
// For SSE, the API requires users to use different endpoints, so we first filter based on
|
// For SSE, the API requires users to use different endpoints, so we first filter based on
|
||||||
|
|
|
@ -3,6 +3,7 @@ use crate::config;
|
||||||
|
|
||||||
pub fn query_for_user_data(access_token: &str) -> (i64, Option<Vec<String>>, Vec<String>) {
|
pub fn query_for_user_data(access_token: &str) -> (i64, Option<Vec<String>>, Vec<String>) {
|
||||||
let conn = config::postgres();
|
let conn = config::postgres();
|
||||||
|
|
||||||
let query_result = conn
|
let query_result = conn
|
||||||
.query(
|
.query(
|
||||||
"
|
"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
//! Provides an interface between the `Warp` filters and the underlying
|
//! Provides an interface between the `Warp` filters and the underlying
|
||||||
//! mechanics of talking with Redis/managing multiple threads.
|
//! mechanics of talking with Redis/managing multiple threads.
|
||||||
//!
|
//!
|
||||||
//! The `ClientAgent`'s interface is very simple. All you can do with it is:
|
//! The `ClientAgent`'s interface is very simple. All you can do with it is:
|
||||||
//! * Create a totally new `ClientAgent` with no shared data;
|
//! * Create a totally new `ClientAgent` with no shared data;
|
||||||
|
|
Loading…
Reference in New Issue