1
0
mirror of https://github.com/actix/examples synced 2025-06-27 01:27:43 +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

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(),
})
}