Skip to content

Commit

Permalink
the sending app url instead of wasm file path for app-url header
Browse files Browse the repository at this point in the history
  • Loading branch information
amitu committed Feb 3, 2025
1 parent 44732d9 commit ae39031
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
35 changes: 16 additions & 19 deletions fastn-core/src/commands/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,22 +516,22 @@ async fn handle_endpoints(
.iter()
.find(|ep| req.path().starts_with(ep.mountpoint.trim_end_matches('/')));

let endpoint = match matched_endpoint {
let (endpoint, app_url) = match matched_endpoint {
Some(e) => {
tracing::info!("matched endpoint: {:?}", e);
e
(e, e.mountpoint.clone())
}
None => {
tracing::info!("no endpoint found in current package. Trying mounted apps");
tracing::info!("request path: {}", req.path());

let app = match config
let (app, app_url) = match config
.package
.apps
.iter()
.find(|a| req.path().starts_with(a.mount_point.trim_end_matches('/')))
{
Some(e) => e,
Some(e) => (e, e.mount_point.clone()),
None => return None,
};

Expand Down Expand Up @@ -567,14 +567,17 @@ async fn handle_endpoints(

tracing::info!("wasm file found: {}", wasm_path);

&fastn_package::old_fastn::EndpointData {
endpoint: format!("wasm+proxy://{wasm_path}"),
mountpoint: format!(
"{app}/{wasm_file}",
app = app.mount_point.trim_end_matches('/')
),
user_id: None, // idk if we're using this
}
(
&fastn_package::old_fastn::EndpointData {
endpoint: format!("wasm+proxy://{wasm_path}"),
mountpoint: format!(
"{app}/{wasm_file}",
app = app.mount_point.trim_end_matches('/')
),
user_id: None, // idk if we're using this
},
app_url,
)
}
};

Expand All @@ -597,13 +600,7 @@ async fn handle_endpoints(

return match config
.ds
.handle_wasm(
url,
req,
endpoint.mountpoint.to_string(),
app_mounts,
session_id,
)
.handle_wasm(url, req, app_url, app_mounts, session_id)
.await
{
Ok(r) => Some(Ok(to_response(r))),
Expand Down
4 changes: 2 additions & 2 deletions fastn-ds/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ impl DocumentStore {
&self,
wasm_url: String,
req: &T,
mountpoint: String,
app_url: String,
app_mounts: std::collections::HashMap<String, String>,
session_id: &Option<String>,
) -> Result<ft_sys_shared::Request, HttpError>
Expand Down Expand Up @@ -510,7 +510,7 @@ impl DocumentStore {
self.pg_pools.clone().into_inner(),
db_path,
fastn_wasm::StoreImpl,
mountpoint,
app_url,
app_mounts,
);
Ok(fastn_wasm::process_http_request(&wasm_url, module, store).await?)
Expand Down
4 changes: 2 additions & 2 deletions v0.5/fastn-wasm/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ impl<STORE: StoreExt> Store<STORE> {
pg_pools: std::sync::Arc<scc::HashMap<String, deadpool_postgres::Pool>>,
db_url: String,
inner: STORE,
mountpoint: String,
app_url: String,
app_mounts: std::collections::HashMap<String, String>,
) -> Store<STORE> {
req.headers
.push((FASTN_APP_URL_HEADER.to_string(), mountpoint.into_bytes()));
.push((FASTN_APP_URL_HEADER.to_string(), app_url.into_bytes()));

let app_mounts = serde_json::to_string(&app_mounts).unwrap();
req.headers
Expand Down

0 comments on commit ae39031

Please sign in to comment.