diff --git a/.env.example b/.env.example index 7f3d3fb..c77c829 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,5 @@ +ADMIN_KEY= + ORDABOK_HOSTS=https://example.com # if empty or unset, CORS will allow all origins # Database diff --git a/src/graphql/context.rs b/src/graphql/context.rs index 4e96fb7..8882a0e 100644 --- a/src/graphql/context.rs +++ b/src/graphql/context.rs @@ -3,11 +3,32 @@ use crate::db::Database; use tracing::info; +macro_rules! from_env { + ($varname:expr) => { + std::env::var($varname) + .expect(format!("{} must be set!", $varname).as_str()) + }; +} + +#[derive(Debug, Clone)] +pub struct OtherEnvVar { + pub admin_key: String, +} + +impl Default for OtherEnvVar { + fn default() -> Self { + Self { + admin_key: from_env!("ADMIN_KEY") + } + } +} + #[derive(Default, Debug, Clone)] pub struct Context { pub db: Database, pub appwrite: APVariables, pub user_auth: bool, + pub other_vars: OtherEnvVar } impl Context {