health route
This commit is contained in:
parent
a406f059e3
commit
89e2772ce6
|
@ -1,7 +1,7 @@
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate diesel;
|
extern crate diesel;
|
||||||
|
|
||||||
use actix_web::{dev::ServiceRequest, web, App, Error, HttpServer};
|
use actix_web::{dev::ServiceRequest, web, App, Error, HttpServer, HttpResponse};
|
||||||
use actix_web_httpauth::{
|
use actix_web_httpauth::{
|
||||||
extractors::{
|
extractors::{
|
||||||
bearer::{BearerAuth, Config},
|
bearer::{BearerAuth, Config},
|
||||||
|
@ -36,6 +36,9 @@ async fn main() -> std::io::Result<()> {
|
||||||
HttpServer::new(move || {
|
HttpServer::new(move || {
|
||||||
let auth = HttpAuthentication::bearer(validator);
|
let auth = HttpAuthentication::bearer(validator);
|
||||||
App::new()
|
App::new()
|
||||||
|
.service(web::resource("/health").to(|| {
|
||||||
|
HttpResponse::Ok().finish()
|
||||||
|
}))
|
||||||
.wrap(auth)
|
.wrap(auth)
|
||||||
.data(pool.clone())
|
.data(pool.clone())
|
||||||
.route("/users", web::get().to(handlers::get_users))
|
.route("/users", web::get().to(handlers::get_users))
|
||||||
|
@ -53,6 +56,7 @@ async fn validator(req: ServiceRequest, credentials: BearerAuth) -> Result<Servi
|
||||||
.app_data::<Config>()
|
.app_data::<Config>()
|
||||||
.map(|data| data.get_ref().clone())
|
.map(|data| data.get_ref().clone())
|
||||||
.unwrap_or_else(Default::default);
|
.unwrap_or_else(Default::default);
|
||||||
|
|
||||||
match auth::validate_token(credentials.token()).await {
|
match auth::validate_token(credentials.token()).await {
|
||||||
Ok(res) => {
|
Ok(res) => {
|
||||||
if res == true {
|
if res == true {
|
||||||
|
|
Loading…
Reference in New Issue