Skip to content

Commit

Permalink
ditch xml, let's just use sitemap.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
djkato committed Jul 10, 2024
1 parent e471bf8 commit 303c122
Show file tree
Hide file tree
Showing 11 changed files with 448 additions and 193 deletions.
15 changes: 15 additions & 0 deletions .neoconf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"lspconfig": {
"rust_analyzer": {
"rust-analyzer.cargo.features": "all"
/*
use this only when working with leptos
*/
// "rust-analyzer.rustfmt.overrideCommand": [
// "leptosfmt",
// "--stdin",
// "--rustfmt"
// ]
}
}
}
12 changes: 0 additions & 12 deletions .neoconf.json.old

This file was deleted.

80 changes: 78 additions & 2 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ leptos_axum = { version = "0.6" }
leptos_meta = { version = "0.6", features = ["nightly"] }
leptos_router = { version = "0.6", features = ["nightly"] }
web-sys = "0.3.69"
rstest = "0.21.0"
async-std = { version = "1.5", features = ["attributes"] }

# Defines a size-optimized profile for the WASM bundle in release mode
[profile.wasm-release]
Expand Down
5 changes: 4 additions & 1 deletion sitemap-generator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ tracing-serde.workspace = true
tracing-subscriber.workspace = true
dotenvy.workspace = true
axum.workspace = true
saleor-app-sdk.workspace = true
saleor-app-sdk = { workspace = true, features = ["file_apl"] }
tower = { workspace = true, features = ["util"] }
tower-http = { workspace = true, features = ["fs", "trace"] }
surf.workspace = true
cynic = { workspace = true, features = ["http-surf"] }
cynic-codegen.workspace = true
thiserror.workspace = true
rstest.workspace = true
async-std = { workspace = true, features = ["attributes"] }

tera = { version = "1.19.1", default-features = false }
fd-lock = "4.0.2"
quick-xml = { version = "0.34.0", features = ["serialize"] }
Expand Down
53 changes: 29 additions & 24 deletions sitemap-generator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ mod app;
mod queries;
mod routes;
mod sitemap;
mod test;

#[cfg(debug_assertions)]
mod tests;

use axum::Router;
use saleor_app_sdk::{
config::Config,
manifest::{cargo_info, AppManifestBuilder, AppPermission},
Expand All @@ -35,13 +38,31 @@ use crate::{
};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
let config = Config::load()?;
trace_to_std(&config)?;
let sitemap_config = SitemapConfig::load()?;
async fn main() {
debug!("Creating configs...");
let config = Config::load().unwrap();
trace_to_std(&config).unwrap();
let sitemap_config = SitemapConfig::load().unwrap();

let app = create_app(&config, sitemap_config).await;

let saleor_app = SaleorApp::new(&config)?;
let listener = tokio::net::TcpListener::bind(
"0.0.0.0:".to_owned()
+ config
.app_api_base_url
.split(':')
.collect::<Vec<_>>()
.get(2)
.unwrap_or(&"3000"),
)
.await
.unwrap();
info!("listening on {}", listener.local_addr().unwrap());
axum::serve(listener, app).await.unwrap();
}

async fn create_app(config: &Config, sitemap_config: SitemapConfig) -> Router {
let saleor_app = SaleorApp::new(&config).unwrap();

debug!("Creating saleor App...");
let app_manifest = AppManifestBuilder::new(&config, cargo_info!())
Expand Down Expand Up @@ -83,27 +104,11 @@ async fn main() -> anyhow::Result<()> {
Ok(v) => v,
Err(e) => {
error!("Missing channel slug, Saleor will soon deprecate product queries without channel specified.");
anyhow::bail!(e);
"".to_string()
}
},
saleor_app: Arc::new(Mutex::new(saleor_app)),
};
debug!("Created AppState...");

let app = create_routes(app_state);
let listener = tokio::net::TcpListener::bind(
"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()?);
match axum::serve(listener, app).await {
Ok(o) => Ok(o),
Err(e) => anyhow::bail!(e),
}
create_routes(app_state)
}
20 changes: 15 additions & 5 deletions sitemap-generator/src/routes/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
use axum::{
handler::HandlerWithoutStateExt,
http::StatusCode,
middleware,
routing::{any, get, post},
Router,
};

#[cfg(not(debug_assertions))]
use axum::middleware;
#[cfg(not(debug_assertions))]
use saleor_app_sdk::middleware::verify_webhook_signature::webhook_signature_verifier;

use tower_http::services::ServeDir;

use crate::app::AppState;
Expand All @@ -22,14 +26,20 @@ pub fn create_routes(state: AppState) -> Router {
(StatusCode::NOT_FOUND, "Not found")
}
let service = handle_404.into_service();
//TODO : Fix this relative path issue in workspaces

#[cfg(not(debug_assertions))]
let serve_dir = ServeDir::new("./public").not_found_service(service);

#[cfg(debug_assertions)]
let serve_dir = ServeDir::new("./sitemap-generator/public").not_found_service(service);
//TODO: Query for everything using the app auth token
//TODO: "Failed fetching initial products: More than one channel exists, please spocify which one"
Router::new()
.route("/api/webhooks", any(webhooks))
.layer(middleware::from_fn(webhook_signature_verifier))
let r = Router::new().route("/api/webhooks", any(webhooks));

#[cfg(not(debug_assertions))]
r.layer(middleware::from_fn(webhook_signature_verifier));

r
//handles just path, eg. localhost:3000/
.route(
"/",
Expand Down
Loading

0 comments on commit 303c122

Please sign in to comment.