Skip to content

Commit

Permalink
feat: allow select HTTP routes to be protected via JWT
Browse files Browse the repository at this point in the history
Signed-off-by: ljedrz <[email protected]>
  • Loading branch information
ljedrz committed Oct 19, 2023
1 parent 39bb04a commit 77f091d
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions node/rest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ impl<N: Network, C: ConsensusStorage<N>, R: Routing<N>> Rest<N, C, R> {
let router = {
axum::Router::new()

// All the endpoints before the call to `route_layer` are protected with JWT auth.
.route("/testnet3/node/address", get(Self::get_node_address))
.route_layer(middleware::from_fn(auth_middleware))

// ----------------- DEPRECATED ROUTES -----------------
// The following `GET ../latest/..` routes will be removed before mainnet.
// Please refer to the recommended routes for each endpoint:
Expand Down Expand Up @@ -157,7 +161,6 @@ impl<N: Network, C: ConsensusStorage<N>, R: Routing<N>> Rest<N, C, R> {
.route("/testnet3/statePath/:commitment", get(Self::get_state_path_for_commitment))
.route("/testnet3/stateRoot/latest", get(Self::get_state_root_latest))
.route("/testnet3/committee/latest", get(Self::get_committee_latest))
.route("/testnet3/node/address", get(Self::get_node_address))

// Pass in `Rest` to make things convenient.
.with_state(self.clone())
Expand All @@ -169,8 +172,6 @@ impl<N: Network, C: ConsensusStorage<N>, R: Routing<N>> Rest<N, C, R> {
.layer(cors)
// Cap body size at 10MB.
.layer(DefaultBodyLimit::max(10 * 1024 * 1024))
// JWT auth.
// .layer(middleware::from_fn(auth_middleware))
};

self.handles.lock().push(tokio::spawn(async move {
Expand Down

0 comments on commit 77f091d

Please sign in to comment.