Skip to content

Commit 42dd024

Browse files
author
Arjen
committed
Merge branch 'pvw-3097-caching-demo-rp' into 'main'
PVW-3097: Use memory-serve in demo RP to prevent undesired caching of assets See merge request wallet/nl-wallet!1081
2 parents e9e2b19 + 7646d1a commit 42dd024

File tree

8 files changed

+114
-23
lines changed

8 files changed

+114
-23
lines changed
File renamed without changes.

wallet_core/Cargo.lock

Lines changed: 81 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wallet_core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ josekit = "0.8.3"
8181
jsonwebtoken = { version = "9.3.0", default-features = false }
8282
lazy_static = "1.4.0"
8383
libsqlite3-sys = { version = "0.27.0", default-features = false }
84+
memory-serve = "0.6.0"
8485
mime = "0.3.17"
8586
mockall = "0.12.1"
8687
nutype = "0.4.0"

wallet_core/mock_relying_party/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ base64.workspace = true
2222
config = { workspace = true, features = ["toml"] }
2323
futures = { workspace = true, features = ["std"] }
2424
http.workspace = true
25+
memory-serve.workspace = true
2526
nutype = { workspace = true, features = ["serde"] }
2627
once_cell.workspace = true
2728
reqwest = { workspace = true, features = ["rustls-tls-webpki-roots"] }
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
const wallet_buttons = document.getElementsByTagName("nl-wallet-button");
1+
const wallet_buttons = document.getElementsByTagName("nl-wallet-button")
22
for (let button of wallet_buttons) {
3-
button.addEventListener(
4-
"success",
5-
(e) => {
6-
if (e.detail && e.detail.length > 1) {
7-
const session_token = e.detail[0];
8-
const session_type = e.detail[1];
9-
const usecase = button.attributes.getNamedItem("usecase").value;
3+
button.addEventListener(
4+
"success",
5+
(e) => {
6+
if (e.detail && e.detail.length > 1) {
7+
const session_token = e.detail[0]
8+
const session_type = e.detail[1]
9+
const usecase = button.attributes.getNamedItem("usecase").value
1010

11-
if (session_type === "cross_device") {
12-
window.location.assign("../" + usecase + "/return?session_token=" + session_token);
13-
}
14-
}
15-
},
16-
false,
17-
);
11+
if (session_type === "cross_device") {
12+
window.location.assign("../" + usecase + "/return?session_token=" + session_token)
13+
}
14+
}
15+
},
16+
false,
17+
)
1818
}

wallet_core/mock_relying_party/src/app.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
use std::{collections::HashMap, env, path::PathBuf, result::Result as StdResult, sync::Arc};
1+
use std::{collections::HashMap, result::Result as StdResult, sync::Arc};
22

33
use askama::Template;
44
use axum::{
55
extract::{Path, Query, State},
6-
handler::HandlerWithoutStateExt,
76
http::{Method, StatusCode},
87
response::{IntoResponse, Response},
98
routing::{get, post},
109
Json, Router,
1110
};
1211
use base64::prelude::*;
12+
use memory_serve::{load_assets, CacheControl, MemoryServe};
1313
use once_cell::sync::Lazy;
1414
use serde::{Deserialize, Serialize};
1515
use tower_http::{
1616
cors::{Any, CorsLayer},
17-
services::ServeDir,
1817
trace::TraceLayer,
1918
};
2019
use tracing::warn;
@@ -87,14 +86,15 @@ pub fn create_router(settings: Settings) -> Router {
8786
wallet_web: settings.wallet_web,
8887
});
8988

90-
let root_dir = env::var("CARGO_MANIFEST_DIR").map(PathBuf::from).unwrap_or_default();
91-
9289
let mut app = Router::new()
9390
.route("/sessions", post(create_session))
9491
.route("/:usecase/", get(usecase))
9592
.route(&format!("/:usecase/{}", RETURN_URL_SEGMENT), get(disclosed_attributes))
9693
.fallback_service(
97-
ServeDir::new(root_dir.join("assets")).not_found_service({ StatusCode::NOT_FOUND }.into_service()),
94+
MemoryServe::new(load_assets!("assets"))
95+
.cache_control(CacheControl::NoCache)
96+
.into_router()
97+
.into_service(),
9898
)
9999
.with_state(application_state)
100100
.layer(TraceLayer::new_for_http());
@@ -182,6 +182,10 @@ static USECASE_JS_SHA256: Lazy<String> =
182182
Lazy::new(|| BASE64_STANDARD.encode(sha256(include_bytes!("../assets/usecase.js"))));
183183

184184
async fn usecase(State(state): State<Arc<ApplicationState>>, Path(usecase): Path<String>) -> Result<Response> {
185+
if !state.usecases.contains_key(&usecase) {
186+
return Ok(StatusCode::NOT_FOUND.into_response());
187+
}
188+
185189
let result = UsecaseTemplate {
186190
usecase: &usecase,
187191
usecase_js_sha256: &USECASE_JS_SHA256,
@@ -197,6 +201,10 @@ async fn disclosed_attributes(
197201
Path(usecase): Path<String>,
198202
Query(params): Query<DisclosedAttributesParams>,
199203
) -> Result<Response> {
204+
if !state.usecases.contains_key(&usecase) {
205+
return Ok(StatusCode::NOT_FOUND.into_response());
206+
}
207+
200208
let attributes = state
201209
.client
202210
.disclosed_attributes(params.session_token, params.nonce)

wallet_core/mock_relying_party/templates/disclosed/attributes.askama

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
{% when "xyz_bank" %}
2323
{% include "xyz_bank.askama" %}
2424
{% else %}
25-
Usecase not found
25+
{% call attributes::attributes(attributes) %}
2626
{% endmatch %}
2727

2828
{# should be last for accessibility purposes #}

wallet_core/mock_relying_party/templates/usecase/usecase.askama

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
{% when "xyz_bank" %}
2424
{% include "xyz_bank.askama" %}
2525
{% else %}
26-
Usecase not found
26+
<nl-wallet-button text="Verder met NL Wallet" usecase="{{ usecase }}" base-url="../"></nl-wallet-button>
2727
{% endmatch %}
2828

2929
{# should be last for accessibility purposes #}

0 commit comments

Comments
 (0)