2020-11-18 16:08:03 +01:00
|
|
|
use actix_cors::Cors;
|
|
|
|
use actix_web::{dev::ServiceRequest, get, App, Error, HttpResponse, HttpServer};
|
2021-08-31 00:27:44 +02:00
|
|
|
use actix_web_httpauth::{extractors::bearer::BearerAuth, middleware::HttpAuthentication};
|
2020-11-18 16:08:03 +01:00
|
|
|
|
|
|
|
async fn ok_validator(
|
|
|
|
req: ServiceRequest,
|
|
|
|
credentials: BearerAuth,
|
2022-07-19 02:40:01 +02:00
|
|
|
) -> Result<ServiceRequest, (Error, ServiceRequest)> {
|
2023-01-07 02:04:16 +01:00
|
|
|
eprintln!("{credentials:?}");
|
2020-11-18 16:08:03 +01:00
|
|
|
Ok(req)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[get("/")]
|
|
|
|
async fn index() -> HttpResponse {
|
|
|
|
HttpResponse::Ok().finish()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[actix_web::main]
|
|
|
|
async fn main() -> std::io::Result<()> {
|
|
|
|
HttpServer::new(move || {
|
|
|
|
App::new()
|
|
|
|
.wrap(HttpAuthentication::bearer(ok_validator))
|
|
|
|
// ensure the CORS middleware is wrapped around the httpauth middleware so it is able to
|
|
|
|
// add headers to error responses
|
|
|
|
.wrap(Cors::permissive())
|
|
|
|
.service(index)
|
|
|
|
})
|
|
|
|
.bind(("127.0.0.1", 8080))?
|
|
|
|
.run()
|
|
|
|
.await
|
|
|
|
}
|