1
0
mirror of https://github.com/actix/examples synced 2025-06-26 17:17:42 +02:00

restructure folders

This commit is contained in:
Rob Ede
2022-02-18 02:01:48 +00:00
parent 4d8573c3fe
commit cc3d356209
201 changed files with 52 additions and 49 deletions

13
cors/backend/Cargo.toml Normal file
View File

@ -0,0 +1,13 @@
[package]
name = "actix-web-cors"
version = "1.0.0"
edition = "2021"
[dependencies]
actix-web = { version = "4.0.0-beta.21", features = ["rustls"] }
actix-cors = "0.6.0-beta.8"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
env_logger = "0.9"
futures = "0.3"

28
cors/backend/src/main.rs Normal file
View File

@ -0,0 +1,28 @@
use actix_cors::Cors;
use actix_web::{http::header, middleware::Logger, App, HttpServer};
mod user;
#[actix_web::main]
async fn main() -> std::io::Result<()> {
std::env::set_var("RUST_LOG", "actix=info");
env_logger::init();
HttpServer::new(move || {
App::new()
.wrap(
Cors::default()
.allowed_origin("http://localhost:8080")
.allowed_methods(vec!["GET", "POST"])
.allowed_headers(vec![header::AUTHORIZATION, header::ACCEPT])
.allowed_header(header::CONTENT_TYPE)
.supports_credentials()
.max_age(3600),
)
.wrap(Logger::default())
.service(user::info)
})
.bind(("127.0.0.1", 8000))?
.run()
.await
}

21
cors/backend/src/user.rs Normal file
View File

@ -0,0 +1,21 @@
use actix_web::{post, web};
use serde::{Deserialize, Serialize};
#[derive(Deserialize, Serialize, Debug)]
pub struct Info {
username: String,
email: String,
password: String,
confirm_password: String,
}
#[post("/user/info")]
pub async fn info(info: web::Json<Info>) -> web::Json<Info> {
println!("=========={:?}=========", info);
web::Json(Info {
username: info.username.clone(),
email: info.email.clone(),
password: info.password.clone(),
confirm_password: info.confirm_password.clone(),
})
}