Formatted files
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use crate::types::*;
|
||||
use crate::AppState;
|
||||
use crate::types::*;
|
||||
use actix_web::web::Data;
|
||||
use actix_web::{get, web, HttpResponse, Responder};
|
||||
use actix_web::{HttpResponse, Responder, get, web};
|
||||
use serde_json::to_string;
|
||||
use sqlx::query_as;
|
||||
|
||||
@@ -49,8 +49,8 @@ async fn get_case_items(query: web::Query<DataUuid>, app_state: Data<AppState>)
|
||||
"SELECT * FROM items_cases WHERE \"case\" = $1",
|
||||
case.id
|
||||
)
|
||||
.fetch_all(&app_state.database)
|
||||
.await;
|
||||
.fetch_all(&app_state.database)
|
||||
.await;
|
||||
if items_cases.is_err() {
|
||||
return HttpResponse::NotFound().finish();
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::types::*;
|
||||
use crate::AppState;
|
||||
use crate::types::*;
|
||||
use actix_web::web::Data;
|
||||
use actix_web::{get, web, HttpResponse, Responder};
|
||||
use actix_web::{HttpResponse, Responder, get, web};
|
||||
use serde_json::to_string;
|
||||
use sqlx::query_as;
|
||||
|
||||
@@ -51,8 +51,8 @@ async fn get_item_cases(query: web::Query<DataUuid>, app_state: Data<AppState>)
|
||||
"SELECT * FROM items_cases WHERE \"item\" = $1",
|
||||
item.id
|
||||
)
|
||||
.fetch_all(&app_state.database)
|
||||
.await;
|
||||
.fetch_all(&app_state.database)
|
||||
.await;
|
||||
if items_cases.is_err() {
|
||||
return HttpResponse::NotFound().finish();
|
||||
}
|
||||
|
||||
21
src/main.rs
21
src/main.rs
@@ -1,4 +1,5 @@
|
||||
mod cases;
|
||||
mod inventories;
|
||||
mod items;
|
||||
mod types;
|
||||
mod users;
|
||||
@@ -10,7 +11,7 @@ use users::*;
|
||||
use utils::*;
|
||||
|
||||
use actix_web::web::Data;
|
||||
use actix_web::{middleware::DefaultHeaders, App, HttpServer};
|
||||
use actix_web::{App, HttpServer, middleware::DefaultHeaders};
|
||||
use sqlx::sqlite::SqlitePool;
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -32,10 +33,14 @@ async fn main() -> std::io::Result<()> {
|
||||
});
|
||||
HttpServer::new(move || {
|
||||
App::new()
|
||||
.wrap(DefaultHeaders::new().add((
|
||||
"Access-Control-Allow-Origin",
|
||||
app_state.allow_origins.join(","),
|
||||
)).add(("Access-Control-Allow-Credentials", "true")))
|
||||
.wrap(
|
||||
DefaultHeaders::new()
|
||||
.add((
|
||||
"Access-Control-Allow-Origin",
|
||||
app_state.allow_origins.join(","),
|
||||
))
|
||||
.add(("Access-Control-Allow-Credentials", "true")),
|
||||
)
|
||||
.service(login)
|
||||
.service(register)
|
||||
.service(logout)
|
||||
@@ -48,7 +53,7 @@ async fn main() -> std::io::Result<()> {
|
||||
.service(options)
|
||||
.app_data(app_state.clone())
|
||||
})
|
||||
.bind(("127.0.0.1", 8000))?
|
||||
.run()
|
||||
.await
|
||||
.bind(("127.0.0.1", 8000))?
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::AppState;
|
||||
use actix_web::web::Data;
|
||||
use actix_web::{options, HttpResponse, Responder};
|
||||
use actix_web::{HttpResponse, Responder, options};
|
||||
|
||||
// This is needed for the web client.
|
||||
// This returns the same options for every path of the api
|
||||
@@ -12,7 +12,10 @@ async fn options(app_state: Data<AppState>) -> impl Responder {
|
||||
app_state.allow_origins.join(","),
|
||||
))
|
||||
.append_header(("Access-Control-Allow-Methods", "GET, OPTIONS"))
|
||||
.append_header(("Access-Control-Allow-Headers", "Content-Type, Authorization"))
|
||||
.append_header((
|
||||
"Access-Control-Allow-Headers",
|
||||
"Content-Type, Authorization",
|
||||
))
|
||||
.append_header(("Access-Control-Allow-Credentials", "true"))
|
||||
.finish()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user