fix how app_url works

This commit is contained in:
Djkáťo 2024-03-21 16:21:01 +01:00
parent 6d7c9b201d
commit 795793ca84
8 changed files with 63 additions and 36 deletions

1
.env
View file

@ -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"

View file

@ -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"

View file

@ -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::<Vec<_>>()
.get(1)
.context("APP_API_BASE_URL invalid format")?,
"0.0.0.0:".to_owned()
+ config
.app_api_base_url
.split(':')
.collect::<Vec<_>>()
.get(2)
.unwrap_or(&"3000"),
)
.await?;
tracing::debug!("listening on {}", listener.local_addr().unwrap());

View file

@ -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"

View file

@ -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),

View file

@ -85,10 +85,10 @@ pub fn get_active_gateways_from_env() -> anyhow::Result<Vec<ActiveGateway>> {
let locale = std::env::var("LOCALE")?;
let locale = LocaleCode::from_str(&locale)?;
let currencies = std::env::var("CURRENCIES")?;
let currencies = currencies.split(",").collect::<Vec<_>>();
let currencies = currencies.split(',').collect::<Vec<_>>();
let currencies = currencies
.iter()
.map(|c| Currency::from_str(*c))
.map(|c| Currency::from_str(c))
.collect::<Result<Vec<_>, _>>()
.map_err(|e| anyhow::anyhow!(format!("{:?}", e)))?;

View file

@ -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::<Vec<_>>()
.get(1)
.context("APP_API_BASE_URL invalid format")?,
"0.0.0.0:".to_owned()
+ config
.app_api_base_url
.split(':')
.collect::<Vec<_>>()
.get(2)
.unwrap_or(&"3000"),
)
.await?;
tracing::debug!("listening on {}", listener.local_addr().unwrap());

View file

@ -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::<Vec<_>>()
.get(1)
.context("APP_API_BASE_URL invalid format")?,
"0.0.0.0:".to_owned()
+ config
.app_api_base_url
.split(':')
.collect::<Vec<_>>()
.get(2)
.unwrap_or(&"3000"),
)
.await?;
info!("listening on {}", listener.local_addr().unwrap());