2019-06-07 23:20:55 +02:00
|
|
|
use actix_web::dev::ServiceRequest;
|
|
|
|
use actix_web::{middleware, web, App, Error, HttpServer};
|
|
|
|
|
|
|
|
use actix_web_httpauth::extractors::basic::BasicAuth;
|
|
|
|
use actix_web_httpauth::middleware::HttpAuthentication;
|
|
|
|
|
2020-01-06 17:00:43 +01:00
|
|
|
async fn validator(
|
2019-06-07 23:20:55 +02:00
|
|
|
req: ServiceRequest,
|
|
|
|
_credentials: BasicAuth,
|
2020-01-06 17:00:43 +01:00
|
|
|
) -> Result<ServiceRequest, Error> {
|
|
|
|
Ok(req)
|
2019-06-07 23:20:55 +02:00
|
|
|
}
|
|
|
|
|
2020-01-06 17:00:43 +01:00
|
|
|
#[actix_rt::main]
|
|
|
|
async fn main() -> std::io::Result<()> {
|
2019-06-07 23:20:55 +02:00
|
|
|
HttpServer::new(|| {
|
|
|
|
let auth = HttpAuthentication::basic(validator);
|
|
|
|
App::new()
|
|
|
|
.wrap(middleware::Logger::default())
|
|
|
|
.wrap(auth)
|
2020-01-06 17:00:43 +01:00
|
|
|
.service(web::resource("/").to(|| async { "Test\r\n" }))
|
2019-06-07 23:20:55 +02:00
|
|
|
})
|
|
|
|
.bind("127.0.0.1:8080")?
|
|
|
|
.workers(1)
|
|
|
|
.run()
|
2020-01-06 17:00:43 +01:00
|
|
|
.await
|
2019-06-07 23:20:55 +02:00
|
|
|
}
|