update actix to version 4

This commit is contained in:
cupcakearmy 2022-03-01 00:53:47 +01:00
parent 1adf87b884
commit 229c8d8368
No known key found for this signature in database
GPG Key ID: 3235314B4D31232F
7 changed files with 337 additions and 918 deletions

1181
backend/Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -11,9 +11,9 @@ path = "src/main.rs"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
actix-web = "3" actix-web = "4"
actix-files = "0.5" actix-files = "0.6"
serde = "1" serde = { version = "1.0", features = ["derive"] }
serde_json = "1" serde_json = "1"
lazy_static = "1" lazy_static = "1"
ring = "0.16" ring = "0.16"

25
backend/src/api.rs Normal file
View File

@ -0,0 +1,25 @@
use actix_web::{get, web, HttpResponse, Responder};
use serde::{Deserialize, Serialize};
use crate::note;
use crate::size::LIMIT;
#[derive(Serialize, Deserialize)]
struct Status {
version: String,
max_size: usize,
}
#[get("/status")]
async fn status() -> impl Responder {
return HttpResponse::Ok().json(Status {
version: option_env!("CARGO_PKG_VERSION")
.unwrap_or("Unknown")
.to_string(),
max_size: *LIMIT,
});
}
pub fn init(cfg: &mut web::ServiceConfig) {
cfg.service(web::scope("/api").service(note::service()).service(status));
}

View File

@ -1,10 +1,10 @@
use actix_files::{Files, NamedFile}; use actix_files::Files;
use actix_web::{web, Responder}; use actix_web::web;
pub fn init(cfg: &mut web::ServiceConfig) { pub fn init(cfg: &mut web::ServiceConfig) {
cfg.service(Files::new("/", "./frontend/build").index_file("index.html")); cfg.service(
} Files::new("/", "./frontend/build")
.index_file("index.html")
pub async fn fallback_fn() -> impl Responder { .use_etag(true),
NamedFile::open("./frontend/build/index.html") );
} }

View File

@ -1,9 +1,10 @@
use actix_web::{middleware, web, App, HttpServer}; use actix_web::{middleware, App, HttpServer};
use dotenv::dotenv; use dotenv::dotenv;
#[macro_use] #[macro_use]
extern crate lazy_static; extern crate lazy_static;
mod api;
mod client; mod client;
mod note; mod note;
mod size; mod size;
@ -17,9 +18,8 @@ async fn main() -> std::io::Result<()> {
.wrap(middleware::Compress::default()) .wrap(middleware::Compress::default())
.wrap(middleware::DefaultHeaders::default()) .wrap(middleware::DefaultHeaders::default())
.configure(size::init) .configure(size::init)
.configure(note::init) .configure(api::init)
.configure(client::init) .configure(client::init)
.default_service(web::resource("").route(web::get().to(client::fallback_fn)))
}) })
.bind("0.0.0.0:5000")? .bind("0.0.0.0:5000")?
.run() .run()

View File

@ -1,4 +1,4 @@
use actix_web::{delete, get, post, web, HttpResponse, Responder}; use actix_web::{delete, get, post, web, HttpResponse, Responder, Scope};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::time::SystemTime; use std::time::SystemTime;
@ -122,16 +122,9 @@ async fn status() -> impl Responder {
}); });
} }
pub fn init(cfg: &mut web::ServiceConfig) { pub fn service() -> Scope {
cfg.service(
web::scope("/api")
.service(
web::scope("/notes") web::scope("/notes")
.service(one) .service(one)
.service(create) .service(create)
.service(delete) .service(delete)
.service(status),
)
.service(status),
);
} }

View File

@ -10,11 +10,9 @@ lazy_static! {
} }
pub fn init(cfg: &mut web::ServiceConfig) { pub fn init(cfg: &mut web::ServiceConfig) {
println!("Limit: {}", *LIMIT);
let json = web::JsonConfig::default().limit(*LIMIT); let json = web::JsonConfig::default().limit(*LIMIT);
let plain = web::PayloadConfig::default() let plain = web::PayloadConfig::default()
.limit(*LIMIT) .limit(*LIMIT)
.mimetype(mime::STAR_STAR); .mimetype(mime::STAR_STAR);
cfg.data(json); cfg.app_data(json).app_data(plain);
cfg.data(plain);
} }