diff --git a/.env b/.env index 4ffda0f..90ad006 100644 --- a/.env +++ b/.env @@ -1,5 +1,6 @@ ## COMMON VARIABLES FOR ALL APPS REQUIRED_SALEOR_VERSION="^3.13" +# only sets port, the host is always 0.0.0.0 (listens to everything). Set this to docker-compose service name APP_API_BASE_URL="http://10.100.110.234:3000" APL="Redis" APL_URL="redis://localhost:6380/2" diff --git a/.env.example b/.env.example index d60974f..a00edf7 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,6 @@ ## COMMON VARIABLES FOR ALL APPS REQUIRED_SALEOR_VERSION="^3.13" +# only sets port, the host is always 0.0.0.0 (listens to everything). Set this to docker-compose service name APP_API_BASE_URL="http://0.0.0.0:3000" APL="Redis" APL_URL="redis://localhost:6379/1" diff --git a/app-template/src/main.rs b/app-template/src/main.rs index 433d824..4d8e064 100644 --- a/app-template/src/main.rs +++ b/app-template/src/main.rs @@ -2,8 +2,8 @@ mod app; mod queries; mod routes; -use anyhow::Context; use saleor_app_sdk::{ + cargo_info, config::Config, manifest::{AppManifest, AppPermission}, webhooks::{AsyncWebhookEventType, WebhookManifest}, @@ -24,7 +24,7 @@ async fn main() -> anyhow::Result<()> { let saleor_app = SaleorApp::new(&config)?; - let app_manifest = AppManifest::new(&config) + let app_manifest = AppManifest::new(&config, cargo_info!()) .add_webhook( WebhookManifest::new(&config) .set_query( @@ -76,12 +76,13 @@ async fn main() -> anyhow::Result<()> { let app = create_routes(app_state); let listener = tokio::net::TcpListener::bind( - &config - .app_api_base_url - .split("//") - .collect::>() - .get(1) - .context("APP_API_BASE_URL invalid format")?, + "0.0.0.0:".to_owned() + + config + .app_api_base_url + .split(':') + .collect::>() + .get(2) + .unwrap_or(&"3000"), ) .await?; tracing::debug!("listening on {}", listener.local_addr().unwrap()); diff --git a/docker-gateway.env b/docker-gateway.env index 6762396..be1202c 100644 --- a/docker-gateway.env +++ b/docker-gateway.env @@ -1,6 +1,8 @@ ## COMMON VARIABLES FOR ALL APPS REQUIRED_SALEOR_VERSION="^3.13" APP_API_BASE_URL="http://0.0.0.0:3001" +MANIFEST_URL="http://0.0.0.0:3001" +CONFIG_URL="http://0.0.0.0:3001" APL="Redis" APL_URL="redis://redis-apl:6379/1" LOG_LEVEL="DEBUG" diff --git a/sdk/src/manifest.rs b/sdk/src/manifest.rs index 4679875..ee4725b 100644 --- a/sdk/src/manifest.rs +++ b/sdk/src/manifest.rs @@ -192,7 +192,28 @@ impl AppManifestBuilder { self.manifest } } +pub struct CargoInfo { + pub name: String, + pub description: String, + pub authors: String, + pub version: String, + pub homepage: String, +} +#[macro_export] +macro_rules! cargo_info { + () => { + saleor_app_sdk::manifest::CargoInfo { + name: env!("CARGO_PKG_NAME").to_owned(), + description: env!("CARGO_PKG_DESCRIPTION").to_owned(), + authors: env!("CARGO_PKG_AUTHORS").to_owned(), + version: env!("CARGO_PKG_VERSION").to_owned(), + homepage: env!("CARGO_PKG_HOMEPAGE").to_owned(), + } + }; +} + +pub use cargo_info; impl AppManifest { /** * Builder for AppManifest @@ -206,22 +227,22 @@ impl AppManifest { * To set webhooks and permissions use the add_webhook() and add_permissions() * */ - pub fn new(config: &Config) -> AppManifestBuilder { + pub fn new(config: &Config, info: CargoInfo) -> AppManifestBuilder { AppManifestBuilder { manifest: AppManifest { - id: env!("CARGO_PKG_NAME").to_owned(), + id: info.name.clone(), required_saleor_version: Some(config.required_saleor_version.clone()), - name: env!("CARGO_PKG_NAME").to_owned(), - about: Some(env!("CARGO_PKG_DESCRIPTION").to_owned()), - author: Some(env!("CARGO_PKG_AUTHORS").to_owned()), - version: env!("CARGO_PKG_VERSION").to_owned(), + name: info.name, + about: Some(info.description), + author: Some(info.authors), + version: info.version, app_url: config.app_api_base_url.clone(), configuration_url: Some(config.app_api_base_url.clone()), token_target_url: format!("{}/api/register", config.app_api_base_url.clone()), permissions: vec![], - homepage_url: Some(env!("CARGO_PKG_HOMEPAGE").to_owned()), - data_privacy_url: Some(env!("CARGO_PKG_HOMEPAGE").to_owned()), - support_url: Some(env!("CARGO_PKG_HOMEPAGE").to_owned()), + homepage_url: Some(info.homepage.clone()), + data_privacy_url: Some(info.homepage.clone()), + support_url: Some(info.homepage.clone()), brand: Some(SaleorAppBranding { logo: SaleorAppBrandingDefault { default: format!("{}/logo.png", config.app_api_base_url), diff --git a/simple-payment-gateway/src/app.rs b/simple-payment-gateway/src/app.rs index b1dbab6..5957d60 100644 --- a/simple-payment-gateway/src/app.rs +++ b/simple-payment-gateway/src/app.rs @@ -85,10 +85,10 @@ pub fn get_active_gateways_from_env() -> anyhow::Result> { let locale = std::env::var("LOCALE")?; let locale = LocaleCode::from_str(&locale)?; let currencies = std::env::var("CURRENCIES")?; - let currencies = currencies.split(",").collect::>(); + let currencies = currencies.split(',').collect::>(); let currencies = currencies .iter() - .map(|c| Currency::from_str(*c)) + .map(|c| Currency::from_str(c)) .collect::, _>>() .map_err(|e| anyhow::anyhow!(format!("{:?}", e)))?; diff --git a/simple-payment-gateway/src/main.rs b/simple-payment-gateway/src/main.rs index a9cc458..b38d323 100644 --- a/simple-payment-gateway/src/main.rs +++ b/simple-payment-gateway/src/main.rs @@ -5,8 +5,8 @@ mod app; mod queries; mod routes; -use anyhow::Context; use saleor_app_sdk::{ + cargo_info, config::Config, manifest::{AppManifest, AppPermission}, webhooks::{SyncWebhookEventType, WebhookManifest}, @@ -33,7 +33,7 @@ async fn main() -> anyhow::Result<()> { let saleor_app = SaleorApp::new(&config)?; - let app_manifest = AppManifest::new(&config) + let app_manifest = AppManifest::new(&config, cargo_info!()) .add_webhook( WebhookManifest::new(&config) .set_query(sub_transaction_process_session) @@ -93,12 +93,13 @@ async fn main() -> anyhow::Result<()> { let app = create_routes(app_state); let listener = tokio::net::TcpListener::bind( - &config - .app_api_base_url - .split("//") - .collect::>() - .get(1) - .context("APP_API_BASE_URL invalid format")?, + "0.0.0.0:".to_owned() + + config + .app_api_base_url + .split(':') + .collect::>() + .get(2) + .unwrap_or(&"3000"), ) .await?; tracing::debug!("listening on {}", listener.local_addr().unwrap()); diff --git a/sitemap-generator/src/main.rs b/sitemap-generator/src/main.rs index 3a053ce..4c88b34 100644 --- a/sitemap-generator/src/main.rs +++ b/sitemap-generator/src/main.rs @@ -4,10 +4,9 @@ mod app; mod queries; mod routes; -use anyhow::Context; use saleor_app_sdk::{ config::Config, - manifest::{AppManifest, AppPermission}, + manifest::{cargo_info, AppManifest, AppPermission}, webhooks::{AsyncWebhookEventType, WebhookManifest}, SaleorApp, }; @@ -32,7 +31,7 @@ async fn main() -> anyhow::Result<()> { debug!("Creating saleor App..."); - let app_manifest = AppManifest::new(&config) + let app_manifest = AppManifest::new(&config, cargo_info!()) .add_permissions(vec![ AppPermission::ManageProducts, AppPermission::ManagePages, @@ -90,12 +89,13 @@ async fn main() -> anyhow::Result<()> { let app = create_routes(app_state); let listener = tokio::net::TcpListener::bind( - &config - .app_api_base_url - .split("//") - .collect::>() - .get(1) - .context("APP_API_BASE_URL invalid format")?, + "0.0.0.0:".to_owned() + + config + .app_api_base_url + .split(':') + .collect::>() + .get(2) + .unwrap_or(&"3000"), ) .await?; info!("listening on {}", listener.local_addr().unwrap());