Skip to content

Commit

Permalink
Merge pull request #10 from Kodylow/allow-cors
Browse files Browse the repository at this point in the history
feat: optionally allow cors for config
  • Loading branch information
elsirion authored Apr 13, 2024
2 parents de6aa05 + 6267035 commit ec4867e
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 6 deletions.
17 changes: 17 additions & 0 deletions Cargo.lock

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

22 changes: 18 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,27 @@ axum = { version = "0.7.5", features = ["json"] }
axum-auth = "0.7.0"
csv = "1.3.0"
dotenv = "0.15.0"
esplora-client = { version = "0.7.0", default-features = false, features = ["async-https-rustls"] }
esplora-client = { version = "0.7.0", default-features = false, features = [
"async-https-rustls",
] }
futures = "0.3.30"
hex = "0.4.3"
reqwest = { version = "0.12.2", default-features = false, features = ["json", "rustls-tls"] }
reqwest = { version = "0.12.2", default-features = false, features = [
"json",
"rustls-tls",
] }
serde = { version = "1.0.197", features = ["derive"] }
serde_json = "1.0.115"
sqlx = {version = "0.7.4", default-features = false, features = ["json", "runtime-tokio", "tls-rustls", "any", "sqlite", "postgres", "macros"]}
tokio = { version = "1.37.0", features = ["full"]}
sqlx = { version = "0.7.4", default-features = false, features = [
"json",
"runtime-tokio",
"tls-rustls",
"any",
"sqlite",
"postgres",
"macros",
] }
tokio = { version = "1.37.0", features = ["full"] }
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
tower-http = { version = "0.5.2", features = ["cors"] }
20 changes: 18 additions & 2 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::collections::HashMap;
use std::env;
use std::sync::Arc;

use axum::extract::{Path, State};
Expand All @@ -17,6 +18,8 @@ use fedimint_ln_common::bitcoin::hashes::hex::ToHex;
use fedimint_ln_common::LightningCommonInit;
use fedimint_mint_common::MintCommonInit;
use fedimint_wallet_common::WalletCommonInit;
use reqwest::Method;
use tower_http::cors::{Any, CorsLayer};
use tracing::warn;

use crate::config::id::fetch_federation_id;
Expand All @@ -34,11 +37,24 @@ pub mod meta;
/// Helper API that exposes the federation modules
pub mod modules;
pub fn get_config_routes() -> Router<AppState> {
Router::new()
let router = Router::new()
.route("/:invite", get(fetch_federation_config))
.route("/:invite/meta", get(fetch_federation_meta))
.route("/:invite/id", get(fetch_federation_id))
.route("/:invite/module_kinds", get(fetch_federation_module_kinds))
.route("/:invite/module_kinds", get(fetch_federation_module_kinds));

let cors_enabled = dotenv::var("ALLOW_CONFIG_CORS").map_or(false, |v| v == "true");

if cors_enabled {
router.layer(
CorsLayer::new()
.allow_origin(Any)
.allow_methods([Method::GET])
.allow_credentials(true),
)
} else {
router
}
}

pub async fn fetch_federation_config(
Expand Down

0 comments on commit ec4867e

Please sign in to comment.