Skip to content

Commit

Permalink
Update to Protect Specific Routes
Browse files Browse the repository at this point in the history
  • Loading branch information
djnovin committed Oct 9, 2024
1 parent fd6660a commit fc18e84
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::env;
use unkey::models::VerifyKeyRequest;
use unkey::Client as UnkeyClient;

async fn middleware(
async fn verify_key(
req: ServiceRequest,
next: Next<impl MessageBody>,
) -> Result<ServiceResponse<impl MessageBody>, Error> {
Expand Down Expand Up @@ -168,11 +168,13 @@ async fn main() -> std::io::Result<()> {
.wrap(Logger::new("%a %{User-Agent}i"))
.app_data(client.clone())
.app_data(shared_data.clone())
.wrap(from_fn(middleware))
// .wrap(from_fn(middleware))
.service(
web::scope("/api/v1")
.route("/public", web::get().to(public))
.route("/protected", web::get().to(protected)),
.route("/protected",
web::get().wrap(from_fn(verify_key)).to(protected)
),
)
})
.bind(("127.0.0.1", port))?
Expand Down

0 comments on commit fc18e84

Please sign in to comment.