Compare commits
4 Commits
c7c3c33686
...
c33f4e6243
| Author | SHA1 | Date | |
|---|---|---|---|
| c33f4e6243 | |||
| b3bd9b6ed2 | |||
| e5fcc4f59c | |||
| f66df87168 |
@@ -10,5 +10,6 @@ serde_json = "1.0.140"
|
||||
sqlx = { version = "0.8.3", features = ["sqlite", "sqlx-macros", "runtime-tokio"] }
|
||||
jsonwebtoken = { version = "9.3.1", features = ["use_pem"] }
|
||||
uuid = { version = "1.15.1", features = ["v4"] }
|
||||
argon2 = "0.6.0-pre.1"
|
||||
rand = "0.9.0"
|
||||
argon2 = { version="0.6.0-pre.1", features = ["std"] }
|
||||
rand = "0.9.0"
|
||||
actix-cors = "0.7.0"
|
||||
@@ -1,4 +1,4 @@
|
||||
use actix_web::{get, web, HttpResponse, Responder};
|
||||
use actix_web::{get, web, HttpResponse, Responder, options};
|
||||
use actix_web::web::Data;
|
||||
use serde_json::to_string;
|
||||
use sqlx::query_as;
|
||||
@@ -16,7 +16,7 @@ async fn get_item(query: web::Query<DataUuid>, app_state: Data<AppState>) -> imp
|
||||
if json.is_err() {
|
||||
return HttpResponse::InternalServerError().finish();
|
||||
}
|
||||
HttpResponse::Ok().body(json.unwrap())
|
||||
HttpResponse::Ok().append_header(("Access-Control-Allow-Origin", "*")).body(json.unwrap())
|
||||
}
|
||||
|
||||
#[get("/items")]
|
||||
|
||||
@@ -2,10 +2,12 @@ mod users;
|
||||
mod cases;
|
||||
mod items;
|
||||
mod types;
|
||||
mod utils;
|
||||
|
||||
use users::*;
|
||||
use cases::*;
|
||||
use items::*;
|
||||
use utils::*;
|
||||
|
||||
use actix_web::web::Data;
|
||||
use actix_web::{App, HttpServer};
|
||||
@@ -17,6 +19,7 @@ struct AppState {
|
||||
token_expiration: u64,
|
||||
}
|
||||
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
let pool = SqlitePool::connect("sqlite:database.db")
|
||||
@@ -37,6 +40,7 @@ async fn main() -> std::io::Result<()> {
|
||||
.service(get_items)
|
||||
.service(get_case_items)
|
||||
.service(get_item_cases)
|
||||
.service(options)
|
||||
.app_data(app_state.clone())
|
||||
})
|
||||
.bind(("127.0.0.1", 8000))?
|
||||
|
||||
@@ -6,7 +6,7 @@ use actix_web::web::{Data, Json};
|
||||
use actix_web::{HttpRequest, HttpResponse, Responder, post};
|
||||
use argon2::Argon2;
|
||||
use argon2::password_hash::{
|
||||
PasswordHash, PasswordHasher, PasswordVerifier, SaltString, rand_core::OsRng,
|
||||
PasswordHash, PasswordHasher, PasswordVerifier, SaltString, rand_core::OsRng
|
||||
};
|
||||
use jsonwebtoken::{
|
||||
Algorithm, DecodingKey, EncodingKey, Header, Validation, decode, encode, get_current_timestamp,
|
||||
|
||||
12
src/utils.rs
Normal file
12
src/utils.rs
Normal file
@@ -0,0 +1,12 @@
|
||||
use actix_web::{options, HttpResponse, Responder};
|
||||
|
||||
// This is needed for the web client.
|
||||
// This returns the same options for every path of the api
|
||||
#[options("/{_:.*}")]
|
||||
async fn options() -> impl Responder {
|
||||
HttpResponse::Ok()
|
||||
.append_header(("Access-Control-Allow-Origin", "*"))
|
||||
.append_header(("Access-Control-Allow-Methods", "GET, OPTIONS"))
|
||||
.append_header(("Access-Control-Allow-Headers", "Content-Type"))
|
||||
.finish()
|
||||
}
|
||||
Reference in New Issue
Block a user